Please note that the recommended version of Scilab is 2023.1.0. This page might be outdated.
See the recommended documentation of this function
bitget
Extracts from integers bits of given indices
Syntax
y = bitget(x, pos)
Parameters
 x
Scalar, vector, matrix or hypermatrix of positive decimal or encoded integers.
 pos
Scalar, vector, matrix or hypermatrix of decimal or encoded integers in
[1, bitmax]
wherebitmax
is the maximal index of bits for the type ofx
: Indices of bits to be extracted. The bit #1 is the lightest one (2^{0}).typeof(x) bitmax .. typeof(x) bitmax int8 7 uint8 8 int16 15 uint16 16 int32 31 uint32 32 int64 63 uint16 64 decimal 1024  y
Scalar, vector, matrix or hypermatrix of 0 and 1 of the type of
x
. The sizes and contents ofy
are as follows:If
x
is a scalar:y
has the sizes ofpos
y(i,j,..)
is the value of bit #pos(i,j,..)
ofx
.
If
pos
is a scalar:y
has the sizes ofx
y(i,j,..)
is the value of the bit #pos
ofx(i,j,..)
.
If
x
andpos
are arrays with identical sizes, the processing is elementwise:y
has the sizes ofx
andpos
y(i,j,..)
is the value of the bit #pos(i,j,..)
ofx(i,j,..)
.
Otherwise:
y
is a matrix withlength(x)
rows andlength(pos)
columns.y(i,j)
is the value of the bit #pos(j)
ofx(i)
.
Description
bitget()
scans chosen bits of the binary representation of some
positive integers x
. It returns 0 for bits down, and 1 for bits up.
The result has the sizes of x
or of pos
or
of both inputs.
However, when both x
and pos
are nonscalar and
have mismatching sizes, the result y
is a matrix ignoring the sizes
of x
. Then, after reshaping y
with
y = matrix(y, [size(x) 1])
, the value of the bit #b of
x(i,..,k)
is in y(i,..,k,b)
.
Examples
// 19 is (10011)_2 // The 2nd bit is 1 (starting from the end). x=uint8(19); pos=2; y = bitget(x,pos) expected = 1; // 13 is (1101)_2 dec2bin(13) bitget(uint8(13),4:1:1)
With arrays and encoded integers::
With big decimal integers > 2^{52}:
x = sum(2 .^([7 16 18 19 25 52 70]1)) bitget(x, [7 16 18 19 35 52 70 80])
> x = sum(2 .^([7 16 18 19 25 52 70]1)) x = 5.903D+20 > bitget(x, [7 16 18 19 35 52 70 80]) ans = Nan Nan 1. 1. 0. 1. 1. 0.
x and pos are arrays with mismatching sizes:
x = [ 39 6 62 8 14 29 4 64 12 44 39 50 52 12 39 5 4 29 ]; x = sum(2.^(x1),2); bitget(x, [5 8 12 39])
> bitget(x, [5 8 12 39]) ans = Nan Nan 0. 1. 0. 1. 0. 0. Nan Nan 1. 0. 0. 0. 0. 1. 0. 0. 1. 1. 1. 0. 0. 0.
See Also
 bitstring — A string giving the literal bit representation of a number
 dec2bin — representação binária
 bitset — Sets bits of given indices in some integers
 bitand — bitwise logical AND between elementwise integers of 2 arrays
 & — Binary AND between integers. Logical AND over/between booleans and numbers
History
Version  Description 
6.1 

Report an issue  
<< bitcmp  Bitwise operations  bitor >> 