1

Working with python 3.5, I recieve a single byte from a PostgreSQL as memoryview.

>>> mybyte
<memory at 0x7fd07b12a888>
>>> bytes(mybyte)
b'\x04' 

How can I read the single Bits of this Byte? Is there a way to get a bitwise representation of this single byte? I thought something like

>>> bin(ord(mybyte))

should do the trick, but it won't work on a memoryview. Also something like

>>> print(mybyte >> 3) 

is clearly not working... Thanks for any hints and support.

1 Answers1

0

Here is one way using binascii:

In [58]: bin(int(binascii.hexlify(var), 16))
Out[58]: '0b100'
Mazdak
  • 105,000
  • 18
  • 159
  • 188