0

## python 十六進位轉二進位並8*8顯屏的困境

str='0x8080808000800000,!'

，即可在key: !時只讀取1 如圖，讓螢幕顯示 !

1. list(test)之後如何兩兩一組?用append?
2.如何讓不足四碼的item補足零?

### 2 個回答

0

iT邦大神 1 級 ‧ 2020-11-28 22:44:18

# 0x1a --> 0b00011010
my_hexdata = "1a"
scale = 16 ## equals to hexadecimal
num_of_bits = 8
bin(int(my_hexdata, scale))[2:].zfill(num_of_bits)

12, IA, 6S, 78 就算了

froce iT邦大師 1 級 ‧ 2020-11-29 23:56:13 檢舉

toro523 iT邦新手 5 級 ‧ 2020-11-30 15:28:33 檢舉

list('x40407C42625C0000') 得個別分開成 ['x','4','0','4'....]，那該如何才能兩兩一組如 ['x4','04','07'...]轉二進位，又或是個別轉二進位後兩兩成一組

0

iT邦大師 1 級 ‧ 2020-11-28 23:28:13
n=101
#For spacing between the each column, based on the integer limit given.
spacing = len(bin(n)[2:])

print ("Decimal".rjust(spacing, ' ')+"Octal".rjust(spacing+1, ' ')+"HexaDeci".rjust(spacing+2, ' ')+"Binary".rjust(spacing, ' '))

for i in range(1,n+1):
print (str(i).rjust(spacing, ' '),str(oct(i)[1:]).replace('o','').rjust(spacing, ' '),str(hex(i)[2:].upper()).rjust(spacing, ' '),str(bin(i)[2:]).rjust(spacing, '0') )
1       1       1 0000001
2       2       2 0000010
3       3       3 0000011
4       4       4 0000100
5       5       5 0000101
6       6       6 0000110
7       7       7 0000111
8      10       8 0001000
9      11       9 0001001
10      12       A 0001010
11      13       B 0001011
12      14       C 0001100
13      15       D 0001101
14      16       E 0001110
15      17       F 0001111
16      20      10 0010000
......
99     143      63 1100011
100     144      64 1100100
101     145      65 1100101