bitget
Get bit at specified position
Description
Examples
Find the difference in the binary representation between the maximum integer of signed and unsigned integers.
a1 = intmax('int8'); a2 = intmax('uint8'); b1 = bitget(a1,8:-1:1)
b1 = 1×8 int8 row vector
0 1 1 1 1 1 1 1
b2 = bitget(a2,8:-1:1)
b2 = 1×8 uint8 row vector
1 1 1 1 1 1 1 1
The signed integers require a bit to accommodate negative integers.
Find the 8-bit representation of a negative number.
A = -29;
b = bitget(A,8:-1:1,'int8')b = 1×8
1 1 1 0 0 0 1 1
Input Arguments
Input values, specified as an array. A can
be a scalar or an array of the same size as bit.
If
Ais a double array, andassumedtypeis not specified, then MATLAB® treatsAas an unsigned 64-bit integer.If
assumedtypeis specified, then all elements inAmust have integer values within the range ofassumedtype.
Data Types: double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64
Bit position, specified as an integer or integer array. bit can
be a scalar or an array of the same size as A. bit must
be between 1 (the least-significant bit) and the number of bits in
the integer class of A.
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
Ais a double array, thenassumedtypecan specify any valid integer type, but defaults to'uint64'.If
Ais an integer type array, thenassumedtypemust specify that same integer type.
Data Types: char | string
Output Arguments
Bit value at bit, returned as an array of 0s
and 1s. b is the same data type
as A.
If
Aandbitare scalars, thenbis also a scalar.If either
Aorbitis an array, thenbis the same size as that array.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
The bitget function
supports GPU array input with these usage notes and limitations:
At least one of input values
Aand bit positionbitmust be an integer data type.The
assumedtypeargument is not supported.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced before R2006a
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.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.
Amerika
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)