Set or clear one or more bits

dim i,a,b,n as byte
'With the objective functions of variables
a.0 = 1  ' set bit 0
b = a.0  ' read bit 0 and save state in b (0 or 1)
n=3
a.n = 1  ' set bit with number in n (3)
'By masking / shifting
a = (1 << 3) ' shift the value "1" three Bits to the left and assign the result to a
b = a and 0b00010000 'mask out bit 4, the state of the bit assigned to b
'Get all the bits one after another
for i=0 to 7   'go through all the bits (byte)
  if a.i then  'get bit state
    'do whatever
  else
    'do other
  end if
next
'assemble a byte from a number of received bits
'With the objective functions of variables
for i=0 to 7   'go through all the bits
  'read state lesen, eg. from a function.
  'Use only the lowest bit of the result.
  a.i = (readState(i) and 0b00000001)
next
 
'with masking and shifting
for i=0 to 7   'go through all the bits
  'read state lesen, eg. from a function.
  'Use only the lowest bit of the result.
  a = a or ((readState(i) and 0b00000001) << i)
next