|
|
Bit extract. Extracts a range of bits from an expression.
Syntax
bitx (source position length)
Formal Declaration
bitx:any (source:any position:s16 length:u16)
Parameters
- source
The value from which to extract a range of bits. Its type is
restricted to the INT and PTR classes.
- position
This parameter specifies the starting bit position (positive value),
or the ending bit position (negative value) of the extraction. Regardless
of the size of the source value, bit positions are always
numbered from left to right. The leftmost bit of the
source is bit 0.
- length
The number of bits to extract. This value may not exceed 64.
This function is sensitive to the type of the source parameter.
If a S32 or U32 value is passed, the format of the word
(start/end positions) is as follows:
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------------------------------------------------------+
| |
+---------------------------------------------------------------+
If a S16 or U16 value is passed, the format of the word
(start/end positions) is as follows:
1 1 1 1 1 1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+-------------------------------+
| |
+-------------------------------+
Examples
This is a 32-bit word containing the bit pattern for the hex value 4015381c:
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+---------------------------------------------------------------+
|0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 1 1 0 0 0 0 0 0 1 1 1 0 0|
+---------------------------------------------------------------+
$nmdebug > var xx:u32 4015381c
$nmdebug > wl bitx(xx,#10,5)
$a
Extract five bits starting at position 10 (this yields the bit pattern 01010).
$nmdebug > wl bitx(xx,-#14,5)
$a
Extract five bits ending at position 14 (this yields the bit pattern 01010).
This is the same field of bits as in the previous example.
Limitations, Restrictions
If an extended address source is passed, the extraction
location must fall entirely within the 64-bit offset part. Since EADDR
types have a total of 96 bits, the valid bit positions are 32 through 95.
|