-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxtime.py
38 lines (34 loc) · 848 Bytes
/
xtime.py
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
def shiftLeft(x):
x = x[1:]
x += '0'
return x
def xor(x):
y = '00011011'
rs = ''
for i in range(0, 8):
if x[i] == y[i]:
rs += '0'
else:
rs += '1'
return rs
def xtime(x):
if x[0] == '0':
x = shiftLeft(x)
else:
x = shiftLeft(x)
x = xor(x)
return x
while True:
ini_string = input('Xtime bao nhiêu? (hex) ( HOAC nhap 0 de thoat ) ')
if ini_string == '0':
break
# Code to convert hex to binary
x = "{0:08b}".format(int(ini_string, 16))
print(f'{ini_string} = {x}')
x = xtime(x)
KQ = ''.join(x)
# hex to bin
decimal_representation = int(KQ, 2)
hexadecimal_string = hex(decimal_representation)
print(f'xtime({ini_string}) = {KQ} ({hexadecimal_string[2:].upper()})')
print('\nTiep tuc nao')