fork(1) download
  1. MAX_BIT = 8 # for 8 bit I2c communication
  2. adat = 0x33 # data to be sent
  3.  
  4. binary = lambda n: n > 0 and [n & 1] + binary(n >> 1) or []
  5.  
  6. res = binary(adat)
  7. num = MAX_BIT - len(res)
  8. cmbnd = [0 for idx in range(num)] + res # combined 8bit
  9.  
  10. print(cmbnd)
  11.  
Success #stdin #stdout 0.02s 27704KB
stdin
Standard input is empty
stdout
[0, 0, 1, 1, 0, 0, 1, 1]