bitcmp

Bit-wise complement of an integer.

Category: Language Fundamentals > Operators and Elementary Operations

Syntax

B = bitcmp(A)

Flips every bit of A within the width of its class.

Description

The number of bits flipped depends on the class: 8 for uint8, 16 for uint16, and so on. Hence bitcmp(uint8(5)) is 250, since 00000101 becomes 11111010. For unsigned types the result equals intmax(class) - A.

Applying bitcmp twice returns the original value.

Input arguments

A
Array of an unsigned integer class, or of nonnegative integer-valued doubles.

Output arguments

B
Array of the same class as A with all bits inverted.

Example

bitcmp(uint8(5))
bitcmp(uint8([0 255]))
bitcmp(uint16(1))
Output
ans = uint8
   250
ans = 1×2 uint8 row vector

   255     0
ans = uint16
   65534

See also

bitand bitor bitxor intmax dec2bin