Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from binascii import unhexlify
- def long_to_bytes(value: int, big_endian: bool) -> bytes:
- # https://stackoverflow.com/a/14527004/3810747
- s = unhexlify(('%%0%dx' % (((width := value.bit_length()) + 8 - ((width % 8) or 8)) // 4)) % value)
- return s if big_endian else s[::-1]
Add Comment
Please, Sign In to add comment