Convert to hex:
cout << hex << int(x) << endl;
How to convert conversely, from hex to dec?
Enter hex number simple:
cin >> hex >> x;
You can use the std::dec
IO manipulator :
std::cout << std::dec << int(x) << endl;
Note that this is only necessary if you have previously used std::hex
or other means to manipulate the base of std::cout
. Otherwise you need take no action: the default for an int
is decimal.
不要使用std::hex
操纵器?
std::cout << int(x) << std::endl;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.