This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Bit-wise complement


cmp = bitcmp(A)
cmp = bitcmp(A,assumedtype)



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


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


collapse all

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

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

original = bitget(A,8:-1:1)
original = 1x8 int8 row vector

   1   1   1   1   0   1   0   1

complement = bitget(bitcmp(A),8:-1:1)
complement = 1x8 int8 row vector

   0   0   0   0   1   0   1   0

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

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

Input Arguments

collapse all

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

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 | string

Output Arguments

collapse all

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

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced before R2006a