import sys

# Depending on the port, the numbers in this test may be implemented as "small"
# native 64 bit ints, arbitrary precision large ints, or large integers using 64-bit
# long longs.

try:
    x = int.from_bytes(b"\x6f\xab\xcd\x12\x34\x56\x78\xfb", "big")
except OverflowError:
    print("SKIP")  # Port can't represent this size of integer at all
    raise SystemExit

print(hex(x))
b = x.to_bytes(8, "little")
print(b)
print(x.to_bytes(8, "big"))

# padding in output
print(x.to_bytes(20, "little"))
print(x.to_bytes(20, "big"))

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

# can't write to a zero-length bytes object
try:
    x.to_bytes(0, "little")
except OverflowError:
    print("OverflowError")

# or one that it too short
try:
    x.to_bytes(7, "big")
except OverflowError:
    print("OverflowError")

# negative representations

x = -x

print(x.to_bytes(8, "little", signed=True))
print(x.to_bytes(20, "big", signed=True))
print(x.to_bytes(20, "little", signed=True))
