Set and Clear bits in TABLE values (Function)

Set and Clear bits in TABLE values (Function)

Here are 2 functions to set and clear a bit in a given TABLE value.

' functions to set and clear bits in TABLE

FUNCTION set_table_bit(index, bit AS INTEGER)
  DIM pattern AS INTEGER
  pattern = 1 << bit
  TABLE(index, TABLE(index) OR pattern)
ENDFUNC

FUNCTION clear_table_bit(index, bit AS INTEGER)
  DIM pattern AS INTEGER
  pattern = NOT (1 << bit)
  TABLE(index, TABLE(index) AND pattern)
ENDFUNC

 

In the main program it is then set_table_bit(100, 4) to set bit 4 of table 100.