“Python int do bajte” Kod odpowiedzi

Konwertuj int na bajt Python

 pythonCopy>>> (258).to_bytes(2, byteorder="little")
b'\x02\x01'
>>> (258).to_bytes(2, byteorder="big")
b'\x01\x02'
>>> (258).to_bytes(4, byteorder="little", signed=True)
b'\x02\x01\x00\x00'
>>> (-258).to_bytes(4, byteorder="little", signed=True)
b'\xfe\xfe\xff\xff'
Frightened Falcon

Python int do bajtów

bytes = (-32757).to_bytes(2, 'little', signed = True) #store value in 2 bytes
#bytes 2 int
print(int.from_bytes([bytes[0], bytes[1]], 'little', signed=True)) #returns -32767

Reinosoft

Python int do bajte

>>> bytes(10)
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
WILLIAM OBIANA

Odpowiedzi podobne do “Python int do bajte”

Pytania podobne do “Python int do bajte”

Więcej pokrewnych odpowiedzi na “Python int do bajte” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu