summaryrefslogtreecommitdiff
path: root/bb.py
blob: dcc82fb4c008f36b28d16cf3c7cd44676419d7ea (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
30
31
32
33
34
35
36
37
38
39
SQR_MASK = (
    0x8000_0000_0000_0000, 0x4000_0000_0000_0000, 0x2000_0000_0000_0000, 0x1000_0000_0000_0000, 0x0800_0000_0000_0000, 0x0400_0000_0000_0000, 0x0200_0000_0000_0000, 0x0100_0000_0000_0000, 
    0x0080_0000_0000_0000, 0x0040_0000_0000_0000, 0x0020_0000_0000_0000, 0x0010_0000_0000_0000, 0x0008_0000_0000_0000, 0x0004_0000_0000_0000, 0x0002_0000_0000_0000, 0x0001_0000_0000_0000, 
    0x0000_8000_0000_0000, 0x0000_4000_0000_0000, 0x0000_2000_0000_0000, 0x0000_1000_0000_0000, 0x0000_0800_0000_0000, 0x0000_0400_0000_0000, 0x0000_0200_0000_0000, 0x0000_0100_0000_0000, 
    0x0000_0080_0000_0000, 0x0000_0040_0000_0000, 0x0000_0020_0000_0000, 0x0000_0010_0000_0000, 0x0000_0008_0000_0000, 0x0000_0004_0000_0000, 0x0000_0002_0000_0000, 0x0000_0001_0000_0000, 
    0x0000_0000_8000_0000, 0x0000_0000_4000_0000, 0x0000_0000_2000_0000, 0x0000_0000_1000_0000, 0x0000_0000_0800_0000, 0x0000_0000_0400_0000, 0x0000_0000_0200_0000, 0x0000_0000_0100_0000, 
    0x0000_0000_0080_0000, 0x0000_0000_0040_0000, 0x0000_0000_0020_0000, 0x0000_0000_0010_0000, 0x0000_0000_0008_0000, 0x0000_0000_0004_0000, 0x0000_0000_0002_0000, 0x0000_0000_0001_0000, 
    0x0000_0000_0000_8000, 0x0000_0000_0000_4000, 0x0000_0000_0000_2000, 0x0000_0000_0000_1000, 0x0000_0000_0000_0800, 0x0000_0000_0000_0400, 0x0000_0000_0000_0200, 0x0000_0000_0000_0100, 
    0x0000_0000_0000_0080, 0x0000_0000_0000_0040, 0x0000_0000_0000_0020, 0x0000_0000_0000_0010, 0x0000_0000_0000_0008, 0x0000_0000_0000_0004, 0x0000_0000_0000_0002, 0x0000_0000_0000_0001)

def render_hex(hex_val: int) -> None:
    if not isinstance(hex_val, int):
        raise ValueError('Input must be integer.')
    if hex_val > 0xFFFF_FFFF_FFFF_FFFF:
        raise ValueError('Input hexadecimal value is too large, must be 64 bits or less.')
    binary_value = bin(hex_val)[2:].zfill(64)
    print('\n', end = '')
    for i in range(0, 64, 8):
        print(*['\x1b[47m' + bit + '\x1b[0m' if bit == '1' else bit for bit in binary_value[i:i+8]])

def switch_bit(bm: int, *idxs: int) -> int:
    for idx in idxs:
        bm ^= SQR_MASK[idx]
    return bm

bm = 0x8080_8080_8080_8080
render_hex(bm)

new_bm = switch_bit(bm)
render_hex(new_bm)

def turn_90_clockw(bm: int) -> int:
    return (bm & 0x0)

num = 0x110
render_hex(num)
newnum = num // 0x4
render_hex(newnum)
print(newnum)