I am trying to understand what from_bytes()
actually does.
The documentation mention this:
The byteorder argument determines the byte order used to represent the integer. If byteorder is "big", the most significant byte is at the beginning of the byte array. If byteorder is "little", the most significant byte is at the end of the byte array. To request the native byte order of the host system, use sys.byteorder as the byte order value.
But this does not really tell me how the bytes values are actually calculated. For example I have this set of bytes:
In [1]: byte = b'xe6x04x00x00'
In [2]: int.from_bytes(byte, 'little')
Out[2]: 1254
In [3]: int.from_bytes(byte, 'big')
Out[3]: 3859021824
In [4]:
I tried ord()
and it returns this:
In [4]: ord(b'xe6')
Out[4]: 230
In [5]: ord(b'x04')
Out[5]: 4
In [6]: ord(b'x00')
Out[6]: 0
In [7]:
I don't see how either 1254
or 3859021824
was calculated from the values above.
I also found this question but it does not seem to explain exactly how it works.
So how is it calculated?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…