HTBasic Help
×
Menu
Index

BIT

Allows any bit in an INTEGER to be tested.
 
 BIT( arg, bit-position )
 
Where:
arg = numeric-expression rounded to an INTEGER
bit-position = numeric-expression rounded to an INTEGER
 
Usage:
Db1=BIT(Db1,4)
Flag=BIT(byte,0)
IF BIT(Byte,Abit) THEN PRINT "Bit #"; Abit;"is on"
 
Example:      BIT.BAS
 
Description:
Use BIT to test any bit in an integer without having to manually search the integer for the desired bit value. The bit positions are numbered from 0 to 15 with 0 being the right-most or least significant bit position. If the bit is set BIT returns a 1, otherwise BIT returns a 0. An example of BIT follows:
 
BIT(12,3)
 
The number 12 is considered a binary number and tested in this manner:
 
12        = 0000000000001100
Bit 3     = 0000000000001000
BIT(12,3) = 1
 
The result is 1 because bit 3 is set in the number 12.
 
See Also: