Skip to content Skip to sidebar Skip to footer

How To Convert From Bytes To Int?

I know that to convert from int to bytes you have to do this, for example: >>>a = bytes(4) >>>print(a) b'\x00\x00\x00\x00' But what do I do if I want to revert i

Solution 1:

importstruct
val = struct.unpack( '<I', b'\x00\x00\x00\x00')[0]

or something along the lines... control the big/little with < or > sign.

Here are the docs: 7.1. struct — Interpret bytes as packed binary data

Post a Comment for "How To Convert From Bytes To Int?"