-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Open
Labels
py-coreRelates to py/ directory in sourceRelates to py/ directory in source
Description
int.to_bytes(size, byteorder) requires one to know how many bytes - size
- the output is but int.bit_length()
is not implemented.
>>> (1024).to_bytes(2, byteorder='big')
b'\x04\x00'
>>> (1024).to_bytes(10, byteorder='big')
b'\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00'
>>> (-1024).to_bytes(10, byteorder='big', signed=True)
b'\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00'
>>> x = 1000
>>> x.to_bytes((x.bit_length() + 7) // 8, byteorder='little')
b'\xe8\x03'
Metadata
Metadata
Assignees
Labels
py-coreRelates to py/ directory in sourceRelates to py/ directory in source