'unrecognized bytes python when convert overflow int to bytes
I know how declare bytes
I used to use hexadecimal notation like this
bita = b'\x01\x02'
I was trying run this simple code
overflow_int = 999999999999999999999999999999999999999999999999999999
bita= int.to_bytes(overflow_int,length=(overflow_int.bit_length()+7)//8,byteorder='big')
print(bita)
print(len(bita))
print(bita[0])
print(b'\np'[0])
print(int.from_bytes(bita,byteorder='big'))
it gave me output
b'\np\xc3\xc4\nd\xe6\xc5\x19\x99\t\x0be\xf6}\x92?\xff\xff\xff\xff\xff\xff'
23
10
10
999999999999999999999999999999999999999999999999999999
In first index of bita, Yes I know why 10 because \n in ascii means newline which it's unprintable ascii and 10th ascii char.
But why b'\np' == b'\n'. Why it includes p? What does it means? Not only that but also symbol-symbol non-alpanumeric like ?{.
Also why len(bita) == 23?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
