0

So I'm a total Python beginner and I got this byte object:

byte_obj = b'\x45\x10\x00\x4c\xcc\xde\x40\x00\x40\x06\x6c\x80\xc0\xa8\xd9\x17\x8d\x54\xda\x28'

But I have no idea how to put this in a binary number, I only know it's gonna have 32 bits.

1 Answer 1

1

You could try int.from_bytes(...), documented here e.g.:

>>> byte_obj = b'\x45\x10\x00\x4c\xcc\xde\x40\x00\x40\x06\x6c\x80\xc0\xa8\xd9\x17\x8d\x54\xda\x28'

>>> int.from_bytes(byte_obj, byteorder='big')
394277201243797802270421732363840487422965373480

Where byteorder is used to specify whether the input is big- or little-endian (i.e. most or least significant byte first).

(Looks a bit bigger than 32 bits though!)

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you I didn't know about that method. What does the byteorder = 'big' do?
It's for specifying if the input bytes are 'big-endian' (most significant byte first) or 'little-endian' (LSB first). I'll update answer to include that detail.
Hi @user16350182, if the answer solved your problem, it would be great if you could mark it as 'accepted' to help others find it more easily.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.