Given n Six positive hexadecimal integers , Output their corresponding octal numbers .
The first line of input is a positive integer n (1<=n<=10).
Next n That's ok , Each line is made up of 09、 Capital AF Composed string , Represents the hexadecimal positive integer to convert , The length of each hexadecimal number does not exceed 100000.
Output n That's ok , Enter the corresponding octal positive integer for each line .
【 Be careful 】
The hexadecimal number you enter will not have a leader 0, such as 012A.
The output octal number also can't have leading 0.
【 Tips 】
First, convert a hexadecimal number to a hexadecimal number , And then from a base number to octal .
2
39
123ABC
71
4435274
n=input()
x=0
shuju=[]
for i in range(int(n)):
m=input()
shuju.append(m)
for i in range(int(n)):
k = oct(int(shuju[i], 16))# Binary conversion
print(k[2:])# Rounding off
1. Hexadecimal conversion
All binary conversions need to be done with int( Number of converted , Original data base type ) Change to decimal for final decimal conversion
2 Hexadecimal to octal oct(int(n,2)) First convert binary to decimal and then convert decimal to octal
Binary system bin()
Decimal system int()
octal oct()
Hexadecimal hex()
2. Remove the hexadecimal symbol at the time of output
Assume the data value is n
Use n[2:] Discard the first two digits of the list