Thread python nach perl -> pack / unpack (10 answers)
Opened by egal123 at 2015-12-09 19:41

foobar12345
 2015-12-09 21:26
#183196 #183196
User since
2011-07-20
20 Artikel
BenutzerIn
[default_avatar]
Code (python): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from bitstring import Bits, pack

bits = pack('uint:5, uint:1, uint:10, uint:8', 2, 0, 64, 2)

byte1, byte2, byte3 = bits.unpack('bytes:1,bytes:1,bytes:1')

listOfBytes = [byte1, byte2, byte3]

checksum  = sum(map(ord, listOfBytes))

if checksum > 511:
    checksum = checksum - 512
if checksum > 255:
    checksum = checksum - 256
if checksum > 127:
    checksum = checksum - 128

bits = pack('uint:5, uint:1, uint:10, uint:8, uint:8', 2, 0, 64, 2, checksum)

Last edited: 2015-12-09 21:37:24 +0100 (CET)

View full thread python nach perl -> pack / unpack