本文介绍了转换十六进制到十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种方法来转换(十六进制) (十六进制)到月 (十进制)容易。我发现了一个简单的方法来做到这一点,如:
INT K = 0x265; COUT<< K<< ENDL;
但随着我不能输入 265 。有反正它的工作这样的:
输入: 265
输出: 613
反正有做到这一点?
注意:我已经试过:
INT K = 0X,B; CIN>> B: COUT<< K + B<< ENDL;和这是行不通的。
解决方案 的#include<的iostream> #包括<了iomanip> 诠释的main() { INT X,Y; 性病:: stringstream的流; 给std :: cin>> X; 流<< X; 流>>性病::十六进制>> ÿ; 性病::法院<< ÿ; 返回0; }I'm looking for a way to convert hex(hexadecimal) to dec(decimal) easily. I found an easy way to do this like :
int k = 0x265; cout << k << endl;But with that I can't input 265. Is there anyway for it to work like that:
Input: 265
Output: 613
Is there anyway to do that ?
Note: I've tried:
int k = 0x, b; cin >> b; cout << k + b << endl;and it doesn't work.
解决方案 #include <iostream> #include <iomanip> int main() { int x, y; std::stringstream stream; std::cin >> x; stream << x; stream >> std::hex >> y; std::cout << y; return 0; }
更多推荐
转换十六进制到十进制
发布评论