python-3-hints

Bitwise Operations

Bit shift something

Shift Right

2<<2
8

Shift Left

  16>>2
  4

Bit Masking

To mask the top 4 bit of an 8bit word (max value 256)

  a=0b10000001
  129

  a & 0x0f
  =>1

Number converting

Converting Number bases

int(num,base) !! Too easy

int('011',2)
3

String a hex

''.join(format(10222224,'02X'))
'9BFA90'

Check

int('9BFA90',16)
10222224

double check

0x9BFA90