Main Content

bitcmp

Bit-wise complement

Description

example

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

example

cmp= bitcmp(A,assumedtype)assumes thatAis ofassumedtype.

Examples

collapse all

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

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

original = bitget(A,8:-1:1)
original =1x8 int8 row vector1 1 1 1 0 1 0 1
补= bitget (bitcmp (A),8:-1:1)
complement =1x8 int8 row vector0 0 0 0 1 0 1 0
cmp = bitcmp(64,'uint8')
cmp = 191
maxint = intmax('uint8') - 64
maxint =uint8191

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.

  • IfAis a double array, andassumedtypeis not specified, then MATLAB®treatsAas an unsigned 64-bit integer.

  • Ifassumedtypeis specified, then all elements inAmust have integer values within the range ofassumedtype.

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

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

  • IfAis a double array, thenassumedtypecan specify any valid integer type, but defaults to'uint64'.

  • IfAis an integer type array, thenassumedtypemust 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.cmpis the same size and type asA.

Extended Capabilities

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

GPU Code Generation
使用GPU CODER™为NVIDIA®GPU生成CUDA®代码。

HDL Code Generation
Generate Verilog and VHDL code for FPGA and ASIC designs using HDL Coder™.

Version History

Introduced before R2006a