0

I have .bmp picture and I need to make some steganography with it.

For this action I have to convert .bmp to list of bytes and then make some changes in bits.

I use open() with "rb" parameter to make bytes list and then convert each byte to string using '{0:08b}'.format(mybyte).

My question is how to convert this string representation of byte back to byte? maybe there are some faster or more correct ways to work with bits?

tshepang
  • 12,111
  • 21
  • 91
  • 136
IvanSorokin
  • 81
  • 11

2 Answers2

1

int constructor can do this very easily :

>>> s = '{0:08b}'.format(42)
>>> s
'00101010'
>>> int(s, 2)
42
Grapsus
  • 2,714
  • 15
  • 14
0

Use binascii module.

Ex:

binascii.a2b_hex('A0')
fred.yu
  • 865
  • 7
  • 10