bits = pack('uint:5, uint:1, uint:10, uint:8', a, b, c, d) byte1, byte2, byte3 = bits.unpack('bytes:1,bytes:1,bytes:1')