|
|
|
| 5 February 2002 | AllFlags() |
| Author | W.M. Hinsch (New Mexico Mark) |
| Action | Given two numbers, returns a boolean true if ALL the '1' bits in the second number are set in the first number, else returns a boolean false. |
| Syntax | AllFlags (NumberToTest, TestNumber) |
| Parameters | |
| Remarks | Developed to test whether one or more bits are set in a given number. I.e. decimal 11 is binary 1011. This means AllFlags() would return true for 1 (0001), 2 (0010), and 8 (1000) as well as 3 (0011), 9 (1001), 10 (1010) and 11 (1011). |
| Returns | Boolean true or false (1 or 0) |
| Dependencies | None. |
| Examples |
'Test against a number with the following bit pattern:' ?
'110011 = 51' ? ?
'&0 = Dec 0' ? ?
'Test 110011 against 000000 (0)' ?
'AllFlags(51,&0)=' + AllFlags(51,Val('&0')) ?
'Test 110011 against 000011 (3)' ?
'AllFlags(51,3)=' + AllFlags(51,3) ?
'Test 110011 against 001100 (12)' ?
'AllFlags(51,12)=' + AllFlags(51,12) ?
'Test 110011 against 010010 (18)' ?
'AllFlags(51,18)=' + AllFlags(51,18) ?
'Test 110011 against 010110 (22)' ?
'AllFlags(51,22)=' + AllFlags(51,22) ? ;AnyFlags() and AllFlags() differ here
110011 = 51
&0 = Dec 0
; Console Output
;Test 110011 against 000000 (0)
;AllFlags(51,&0)=0
;Test 110011 against 000011 (3)
;AllFlags(51,3)=1
;Test 110011 against 001100 (12)
;AllFlags(51,12)=0
;Test 110011 against 010010 (18)
;AllFlags(51,18)=1
;Test 110011 against 010110 (22)
;AllFlags(51,22)=0
|
| Source |
FUNCTION AllFlags ($inum, $itst)
; Returns a boolean true if all the '1' bits in $iTst are also set in $iNum.
$inum=Val($inum)
$itst=Val($itst)
IF ($itst = 0)
$allflags=0
EXIT
ENDIF
$allflags=(($inum & $itst) = $itst)
ENDFUNCTION ; - AllFlags -
|
|
|
|