Accelerating the pace of engineering and science

# Documentation Center

• Trial Software

# bitcmp

Bit-wise complement

bitcmp(A,N) will not accept N in a future release. Use bitcmp(A) or bitcmp(A,assumedtype) instead.

## Syntax

• cmp = bitcmp(A,N)

## Description

example

cmp = bitcmp(A) returns the bit-wise complement of A.

example

cmp = bitcmp(A,assumedtype) assumes that A is of assumedtype.

cmp = bitcmp(A,N) returns an N-bit complement of A. Elements of A cannot exceed 2N-1.

## Examples

expand all

### Complement of a Negative Integer

```A = int8(-11);
cmp = bitcmp(A)```
```cmp =

10```

You can see the complement operation when the numbers are shown in binary.

```original = bitget(A,8:-1:1)
complement = bitget(bitcmp(A),8:-1:1)```
```original =

1    1    1    1    0    1    0    1

complement =

0    0    0    0    1    0    1    0```

### Complement of Unsigned Integers

```cmp = bitcmp(64,'uint8')
maxint = intmax('uint8') - 64```
```cmp =

191

maxint =

191```

The complement of an unsigned integer is equal to itself subtracted from the maximum integer of its data type.

## Input Arguments

expand all

### A — Input valuesigned integer array | unsigned integer array | double array

Input value, specified as a signed integer array, unsigned integer array, or double array.

• If A is a double array, and assumedtype is not specified, then MATLAB treats A as an unsigned 64-bit integer.

• If assumedtype is specified, then all elements in A must have integer values within the range of assumedtype.

Data Types: double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

### assumedtype — Assumed data type of A'uint64' | 'uint32' | 'uint16' | 'uint8' | 'int64' | 'int32' | 'int16' | 'int8'

Assumed data type of A, specified as 'uint64', 'uint32', 'uint16', 'uint8', 'int64', 'int32', 'int16', or 'int8'.

• If A is a double array, then assumedtype can specify any valid integer type, but defaults to 'uint64'.

• If A is an integer type array, then assumedtype must specify that same integer type.

Data Types: char

### N — number of returned bitsinteger

Number of returned bits, specified as an integer. N cannot exceed the number of bits in the integer type of A.

Data Types: double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

## Output Arguments

expand all

### cmp — Bit-wise complementsigned integer array | unsigned integer array | double array

Bit-wise complement, returned as a signed integer array, unsigned integer array, or double array. cmp is the same size and type as A.