Bits Procedure |
Version 10 |
Returns or sets bits value, of given bit position and count. If the last parameter is missing, then it returns bit value. Otherwise it returns the resulting value of bit operation.
[ dwReturn = ] Bits ( dw, lBitsStart, lBitsCount, [dwValue] )
The Bit procedure syntax has the following parts:
Name |
Type |
Description |
dwReturn |
DWord |
Returned value: either bit value, 0 or 1, or if dwValue is provided - resulting value of the bit operation |
dw |
Val DWord |
Input value in DWord |
lBitsStart |
Val Long |
Starting bit position, 0 based, possible values is 0 to 31. |
lBitsCount |
Cal Long |
Number of bits to get or set |
dwValue |
Val DWord |
Value to set the bits. If this parameter is omitted, dwReturn returns bits value of given position and count. If this parameter is provided, dwReturn returns dw value with the specified bits count at lBitsStart bit set. |
Use this function to get or set a bit field from an integer (similar to a C programming language structure bit field). If dwValue is passed the function returns the dw with the bits specified set to dwValue.
The following example shows using the Bit function to get and set values:
dw=0x300
print bits(dw, 8, 2), str(dw, 2) ! 2 11
dw=bits(dw, 6, 2, 3)
print str(dw, 16), str(dw, 2) ! 3C0 1111000000
dw=bits(dw, 30, 2, 3)
print str(dw, 16), str(dw, 2) ! C0003CO 11000000000000000000001111000000