bitcmp
Bit-wise complement
Description
Examples
Complement of a Negative Integer
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
Complement of Unsigned Integers
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
A
—Input value
signed integer array|unsigned integer array|双阵列
Input value, specified as a signed integer array, unsigned integer array, or double array.
If
A
is a double array, andassumedtype
is not specified, then MATLAB®treatsA
as an unsigned 64-bit integer.If
assumedtype
is specified, then all elements inA
must have integer values within the range ofassumedtype
.
Data Types:double
|int8
|int16
|int32
|int64
|uint8
|uint16
|uint32
|uint64
assumedtype
—Assumed data type ofA
'uint64'
|'uint32'
|'uint16'
|'uint8'
|'int64'
|'int32'
|'int16'
|'int8'
Assumed data type ofA
, specified as'uint64'
,'uint32'
,'uint16'
,'uint8'
,'int64'
,'int32'
,'int16'
, or'int8'
.
If
A
is a double array, thenassumedtype
can specify any valid integer type, but defaults to'uint64'
.If
A
is an integer type array, thenassumedtype
must specify that same integer type.
Data Types:char
|string
Output Arguments
cmp
— Bit-wise complement
签名整数数组|未签名的整数数组|双阵列
Bit-wise complement, returned as a signed integer array, unsigned integer array, or double array.cmp
is 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™.
Thread-Based Environment
Run code in the background using MATLAB®backgroundPool
or accelerate code with Parallel Computing Toolbox™ThreadPool
.
This function fully supports thread-based environments. For more information, seeRun MATLAB Functions in Thread-Based Environment.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
Usage notes and limitations:
The input argument
A
must be agpuArray
of unsigned integers.64-bit integers are not supported.
The
assumedtype
argument is not supported.
For more information, seeRun MATLAB Functions on a GPU(Parallel Computing Toolbox).
Version History
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- Denmark(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)