Python: How do I extract specific bits from a byte?

To answer the second part of your question, you can get specific bit values using bitwise operations

# getting your message as int
i = int("140900793d002327", 16)

# getting bit at position 28 (counting from 0 from right)
(i >> 28) & 1

# getting bits at position 24-27
bin((i >> 24) & 0b111)

Leave a Comment