user20144486
user20144486

Reputation:

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

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

Upvotes: 1

Views: 48

Answers (1)

Federico Beach
Federico Beach

Reputation: 65

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

Upvotes: 4

Related Questions