Get bit at specified position
b = bitget(A,bit)
b = bitget(A,bit,assumedtype)
example
b = bitget(A,bit) returns the bit value at position bit in integer array A.
b
A
bit
b = bitget(A,bit,assumedtype) assumes that A is of assumedtype.
assumedtype
collapse all
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 = 1x8 int8 row vector 0 1 1 1 1 1 1 1
b2 = bitget(a2,8:-1:1)
b2 = 1x8 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 values, specified as an array. A can be a scalar or an array of the same size as bit.
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
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.
'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 | string
char
string
Bit value at bit, returned as an array of 0s and 1s. b is the same data type as A.
0
1
If A and bit are scalars, then b is also a scalar.
If either A or bit is an array, then b is the same size as that array.
Usage notes and limitations:
Both inputs can be unsigned integer arrays, or one input can be an unsigned integer array and the other input can be a scalar double.
64-bit integers are not supported.
The assumedtype argument is not supported.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
bitand | bitcmp | bitor | bitset | bitshift | bitxor | intmax
bitand
bitcmp
bitor
bitset
bitshift
bitxor
intmax
You have a modified version of this example. Do you want to open this example with your edits?