Skip to content
Advertisement

Tag: byte

Get size in Bytes needed for an integer in Python

How can I find out the number of Bytes a certain integer number takes up to store? E.g. for hexadecimal x00 – xff (or decimal 0 – 255 = binary 0000 0000 – 1111 1111) I’m looking to get 1 (Byte), hexadecimal x100 – xffff (or decimal 256 – 65535 = binary 0000 0001 0000 0000 – 1111 1111 1111

What is the difference between a string and a byte string?

I am working with a library which returns a “byte string” (bytes) and I need to convert this to a string. Is there actually a difference between those two things? How are they related, and how can I do the conversion? Answer Assuming Python 3 (in Python 2, this difference is a little less well-defined) – a string is a

Using Python How can I read the bits in a byte?

I have a file where the first byte contains encoded information. In Matlab I can read the byte bit by bit with var = fread(file, 8, ‘ubit1’), and then retrieve each bit by var(1), var(2), etc. Is there any equivalent bit reader in python? Answer Read the bits from a file, low bits first.

Advertisement