|
Home Site Structure Programming Home Basic Home GUI & OS Home QB Knowledge Base Professor Answers Codename Surena QB Downloads Write Us
Special LinksQB DirectoryNEW Codename Surena Forums |
|
||
How to get/set a bit within a binary number? Suppose you want to check to bit number n of the value stored in LONG INTEGER variable "var". You may AND the value with 2^n. If the result is non-zero the bit is set, otherwise, it is not: IF var AND 2 ^ n THEN 'The bit is set. ELSE 'The bit is clear. END IF Remember that the bit are numbered from right to left beginning at 0. If you want to set bit number n of the value stored in LONG INTEGER variable "var". You may OR the value with 2^n: var = var OR 2 ^ n And if you want to clear that bit, simply AND the value with the invert of 2^n: var = var OR (NOT 2 ^ n) |