Decimal conversion hex Problem
Main topic:
Converts a decimal integer to 16, in the form of 0x, 10~15 is represented by an uppercase letter, a~f.
Requirements:
Input
One integer per line x,0<= x <= 2^31.
Output
Each row outputs a corresponding eight-bit hexadecimal integer, including the leading 0.
Input Sample:
Input
0
1023
Output
0x00000000
0x000003ff
Topic Analysis:
Output in hexadecimal format converter
Program code:
1#include <cstdio>2#include <iostream>3 using namespacestd;4 5 intMain ()6 {7 intx;8 while(cin>>x)//Enter multiple sets of cases9 {Tenprintf"0x%.8x\n", x);//output in hexadecimal format One } A return 0; -}
Experience:
Just see the topic is to think of the topic is very complex, both in 16 in the form of output, but also the output of capital letters, the output of the time includes the leading 0, see the topic is not know how to do, and then carefully think of the original is very simple, as long as with printf ("0x%08X", X); Where 0x itself outputs, 08 means the output is 8 hexadecimal, and X is output in uppercase letters, so that the requirements can be satisfied. In fact, this is a very simple topic, think about it will find only the most basic knowledge of C language.
Match-decimal conversion hex-Problem Solving report