将hex缓冲区转换为unsigned int [英] convert hex buffer to unsigned int
本文介绍了将hex缓冲区转换为unsigned int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试将保存在缓冲区中的十六进制数转换为unsigned int。然而,在我读取的每个十六进制数字前面的0x00一直给我的问题,本质上,问题(在缩减版本)看起来像这样:
I've been trying to convert a hexadecimal number saved in a buffer to an unsigned int. However the "0x00" in front of every hexadecimal number that I'm reading from has been giving me problem, in essence the problem (in a downscaled version) looks like this:
char b[] = "0x0014A12";
std::stringstream ss;
unsigned int i;
ss << std::hex << b;
ss >> i;
cout << i << endl;
任何提示?
注意:程序输出一个高十进制的小数,等于十六进制的CCCCCC。
Note: The program outputs a high decimal nubmer which equals CCCCCC in hex.
推荐答案
这对我来说很好:
#include <iostream>
#include <sstream>
int main(int argc, char* argv[])
{
using namespace std;
string b("0x0014A12");
stringstream ss;
ss << hex << b;
unsigned int dec;
ss >> dec;
cout << b << " = " << dec << endl;
return 0;
}
输出:
0x0014A12 = 84498
这篇关于将hex缓冲区转换为unsigned int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文