summaryrefslogtreecommitdiff
path: root/tests/basics/int_bytes_intbig.py
blob: b19c8ae53ee09ace5beca3106f93ce56aa3010de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import skip_if
skip_if.no_bigint()

print((2**64).to_bytes(9, "little"))
print((2**64).to_bytes(9, "big"))

b = bytes(range(20))

il = int.from_bytes(b, "little")
ib = int.from_bytes(b, "big")
print(il)
print(ib)
print(il.to_bytes(20, "little"))
print(ib.to_bytes(20, "big"))

# check that extra zero bytes don't change the internal int value
print(int.from_bytes(b + bytes(10), "little") == int.from_bytes(b, "little"))

# too small buffer should raise an error
try:
    (2**64).to_bytes(8, "little")
except OverflowError:
    print("OverflowError")

# negative numbers should raise an error
try:
    (-2**64).to_bytes(9, "little")
except OverflowError:
    print("OverflowError")