Never been to DZone Snippets before?

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

Reading bytes value (See related posts)

from struct import unpack
f = open('data.bin', 'rb')

b = f.read(1)
b2 = f.read(2)
b4 = f.read(4)

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

You need to create an account or log in to post comments to this site.


Click here to browse all 5147 code snippets

Related Posts