struct.unpack and int conversion for binary string returns different results

Viewed 31

I'm trying to execute the code below:

import struct

result1 = struct.unpack("I", bytearray([247, 3, 2, 99]))[0]
print(result1)
print(int("11110111", 2), 247)
print(int("00000011", 2), 3)
print(int("00000010", 2), 2)
print(int("01100011", 2), 99)
print(int("11110111000000110000001001100011", 2))

Output:

1661076471
247 247
3 3
2 2
99 99
4144169571

The output for bytearray([247, 3, 2, 99] is 1661076471 how can I convert int("11110111000000110000001001100011", 2) to 1661076471 right now it is 4144169571.

0 Answers
Related