extract specified bits from a number
GetBits(number, locns, options)
a single or sequence of locations or ranges
The GetBits command extracts the specified bits from a number. The locns argument can be a sequence of bit locations or bit location ranges, including negative ranges and negative offsets. Note that all bit locations are given with 0 as the location of the least significant bit. For example, -1..0 can be used to extract the bits in a number in reverse order.
The optional arguments for GetBits are as follows:
output=form: where form can be sequence (the default), or number. When form is specified as sequence, the output will be in the form of a sequence of 0's and 1's corresponding to the specified bit locations. When form is specified as number, the bit sequence will be used to construct a number, where the first bit in locns will be the least significant bit in the output number.
bits=count: specifies the number of bits in the input number. Any bit references that exceed this value will have a value of zero. Any negative bit references that go past the least significant bit will return an error. The default bits value can be set via Settings.
num ≔ Join⁡1,1,0,0,0,1,0,1,0,1,1,0,1,1,1
Get least significant bit.
Get most significant bit. (This will be 1 if bits is not specified.)
Get most significant bit assuming input is 16 bits
Extract all bits - this is the same as Split
Reverse order of the bits as a 16 bit number
Reverse order as a 16 bit number with number output is equivalent to extracting in reverse above followed by join
Exchange first 8 bits and last 8 bits in a 16 bit number
num2 ≔ GetBits⁡num,8..15,0..7,output=number
Download Help Document