We would display Hexadecimals in A03Eh format which A=10 & 开发者_C百科E=14, and A is a nibble. But I have seen another display like this : 0x002314A8 , How can we convert the above number into this format ? what is this format ?
int a = 0x002314A8;
printf("a = 0x%08X", a);
or
std::out << "a = 0x" << std::hex << std::uppercase << std::setfill('0') << std::setw(8) << std::setprecision(8) << a ;
The format 0x
is the standard Unix way of representing hexadecimal numbers. I am used to seeing 0x
at the beginning and not h
at the end.
That is the only difference. Like Péter Török said, if you're using C/C++ there are ways to modify what is shown when you print.
Write a function that takes an integer and returns a string in that format. Then call it like this:
std::cout << toHex(0xA03E);
It shouldn't be that difficult a function to write. Using the ios::hex manipulator will display your number in the 0x format. Is that what you wanted?
精彩评论