Octal to hexadecimal, hexadecimal

Source: Internet
Author: User

Octal to hexadecimal, hexadecimal

Input

The first act is an integer T, indicating the number of data groups.

There is an octal numeric string per line in Line T.

 

Output

The hexadecimal string corresponding to each group of data output

 

 

Sample Input

4
7
77
233
2333333333333333333

 

Sample Output

7
3F
9B
9B6DB6DB6DB6DB Code:

# Include <iostream>
# Include <string>
Using namespace std;
Char x (int n ){
If (n <= 9)
Return n + '0 ';
Switch (n ){
Case 10: return 'a ';
Case 11: return 'B ';
Case 12: return 'C ';
Case 13: return 'D ';
Case 14: return 'E ';
Case 15: return 'F ';
}
}
Int main (){
Int t, I, num, n1, n2, n3, j, k;
String str;
Char str1 [10000];
Cin> t;
While (t --){
Str. clear ();
J = 0;
Cin> str;
I = str. size ()-1;
For (; I> 3; I-= 4 ){
Num = str [I]-'0' + (str [I-1]-'0') * 8 + (str [I-2]-'0 ') * 64 + (str [I-3]-'0') * 512;
N1 = 0, n2 = 0, n3 = 0;
While (num> 0 ){
If (num> = 16*16 ){
Num-= 16*16;
N1 ++;
}
Else if (num> = 16 ){
Num-= 16;
N2 ++;
}
Else {
N3 = num;
Break;
}
}
Str1 [j ++] = x (n3 );
Str1 [j ++] = x (n2 );
Str1 [j ++] = x (n1 );
}
Num = 0, n1 = 0, n2 = 0, n3 = 0;
For (k = 0; k <= I; ++ k)
Num = num * 8 + str [k]-'0 ';
While (num> 0 ){
If (num> = 16*16 ){
Num-= 16*16;
N1 ++ ;}
Else if (num> = 16 ){
Num-= 16;
N2 ++ ;}
Else {
N3 = num;
Break ;}
}
Str1 [j ++] = x (n3 );
Str1 [j ++] = x (n2 );
Str1 [j ++] = x (n1 );
If (n1 = 0 ){
J --;
If (n2 = 0)
J --;
}
While (-- j)
Cout <str1 [j];
Cout <str1 [j] <endl;

}

Return 0;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.