2014-04-09 20:45:38 -04:00
|
|
|
import struct
|
|
|
|
print(struct.calcsize("<bI"))
|
|
|
|
print(struct.unpack("<bI", b"\x80\0\0\x01\0"))
|
2014-04-10 15:19:32 -04:00
|
|
|
print(struct.calcsize(">bI"))
|
|
|
|
print(struct.unpack(">bI", b"\x80\0\0\x01\0"))
|
2014-04-10 20:47:21 -04:00
|
|
|
|
|
|
|
# 32-bit little-endian specific
|
|
|
|
#print(struct.unpack("bI", b"\x80\xaa\x55\xaa\0\0\x01\0"))
|
2014-04-18 20:13:15 -04:00
|
|
|
|
|
|
|
print(struct.pack("<i", 1))
|
|
|
|
print(struct.pack(">i", 1))
|
|
|
|
print(struct.pack("<h", 1))
|
|
|
|
print(struct.pack(">h", 1))
|
|
|
|
print(struct.pack("<b", 1))
|
|
|
|
print(struct.pack(">b", 1))
|
|
|
|
|
|
|
|
print(struct.pack("<bI", -128, 256))
|
|
|
|
print(struct.pack(">bI", -128, 256))
|
2014-05-12 16:45:50 -04:00
|
|
|
|
|
|
|
print(struct.calcsize("100sI"))
|
|
|
|
print(struct.calcsize("97sI"))
|
|
|
|
print(struct.unpack("<6sH", b"foo\0\0\0\x12\x34"))
|
|
|
|
print(struct.pack("<6sH", b"foo", 10000))
|