DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Reading Bytes Value

  • submit to reddit
from struct import unpack
f = open('data.bin', 'rb')

b =
b2 =
b4 =

n = ord(b)  # from char to int
n4 = unpack('>L', b4)  # big endian
n4 = unpack('<L', b4)  # little endian
n = unpack('>h', b2)   # big endian short