MATLAB Function Reference  bitcmp

Return bitwise complement

Syntax

• ```C = bitcmp(A)
C = bitcmp(A, n)
```

Description

```C = bitcmp(A) ``` returns the bitwise complement of `A`, where `A` is an unsigned integer or an array of unsigned integers.

```C = bitcmp(A, n) ``` returns the bitwise complement of `A` as an `n`-bit unsigned integer `C`. Input `A` may not have any bits set higher than `n` (that is, `A` may not have a value greater than `2^n-1`). The value of `n` can be no greater than the number of bits in the unsigned integer class of `A`. For example, if the class of `A` is `uint32`, then `n` must be a positive integer less than 32.

Examples

Example 1

With eight-bit arithmetic, the one's complement of 01100011 (decimal 99) is 10011100 (decimal 156):

• ```C = bitcmp(uint8(99))
C =
156
```

Example 2

The complement of hexadecimal A5 (decimal 165) is 5A:

• ```x = hex2dec('A5')
x =
165

dec2hex(bitcmp(x, 8))
ans =
5A
```

Next, find the complement of hexadecimal 000000A5:

• ```dec2hex(bitcmp(x, 32))
ans =
FFFFFF5A
```

See Also

`bitand`, `bitget`, `bitmax`, `bitor`, `bitset`, `bitshift`, `bitxor`

© 1994-2005 The MathWorks, Inc.