IB Statements/setbit
From CometWiki
SETBIT function
Discussion: The SETBIT function sets the specified bit in a string expression.
Syntax: Result = SETBIT(string-expression, bit-location, bit-value [,EXCP=label])
Where: Result contains the value of the bit before it was set. Valid values are 0 and 1.
String-expression is a string value encoded in binary form.
Bit-location is a numeric value specifying the bit that is to be set.
Bits are 0-based and are ordered according to the following scheme:
If the string-expression contains 8 bits, they are ordered:
7 6 5 4 3 2 1 0
If the string-expression contains 16 bits, they are ordered:
7 6 5 4 3 2 1 0 15 14 13 12 11 10 9 8
If the string-expression contains 24 bits, they are ordered:
7 6 5 4 3 2 1 0 15 14 13 12 11 10 9 8 23 22 21 20 19 18 17 16
Bit-value is 0 or 1.
An exception occurs if the program attempts to set a bit beyond the declared length of the string-expression.
Example:
A$ = “@0000@” ! B$ = HEXASC(A$) Print “Before:”;B$ ! FOR I = 8 TO 11 J = SETBIT(A$,I,1,EXCP=9999) Print “Bit”;I;”was”;J NEXT I ! B$ = HEXASC(A$) Print “After”;B$