Why do i get the same result even with different byteorder?

Question:

This is when we convert numbers to bytes :

print(int.to_bytes(65, length=1, byteorder='big')) #this converts numbers to characters

result:

A

why do i see the same result even if i used different byteorder ?

print(int.from_bytes(b'A', byteorder='big', signed=True))
print(int.from_bytes(b'A', byteorder='little', signed=True))

result:

65
65
Asked By: Essence

||

Answers:

Probably because one char (‘A’) is stored in a single byte. The change of order big/little is visible with many bytes. Tested with 2 different bytes:

>>> print(int.from_bytes(b'AB', byteorder='big', signed=True))
16706
>>> print(int.from_bytes(b'AB', byteorder='little', signed=True))
16961

See python docs

Answered By: Federico Beach
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.