Bits[GetBits] - extract specified bits from a number
|
Calling Sequence
|
|
GetBits(number, locns)
GetBits(number, locns, options)
|
|
Parameters
|
|
number
|
-
|
an integer
|
locns
|
-
|
a single or sequence of locations or ranges
|
options
|
-
|
optional arguments
|
|
|
|
|
Description
|
|
•
|
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.
|
|
Examples
|
|
>
|
|
>
|
|
| (1) |
Get least significant bit.
>
|
|
| (2) |
Get most significant bit. (This will be 1 if bits is not specified.)
>
|
|
| (3) |
Get most significant bit assuming input is 16 bits
>
|
|
| (4) |
Extract all bits - this is the same as Split
>
|
|
| (5) |
>
|
|
| (6) |
Reverse order of the bits as a 16 bit number
>
|
|
| (7) |
Reverse order as a 16 bit number with number output is equivalent to extracting in reverse above followed by join
>
|
|
| (8) |
>
|
|
| (9) |
Exchange first 8 bits and last 8 bits in a 16 bit number
>
|
|
| (10) |
Check:
>
|
|
| (11) |
>
|
|
| (12) |
|
|
Download Help Document
Was this information helpful?