C ++十六进制字符串到unsigned int [英] C++ hex string to unsigned int
本文介绍了C ++十六进制字符串到unsigned int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
C ++将十六进制字符串转换为有符号整数
Possible Duplicate:
C++ convert hex string to signed integer
我正在尝试将十六进制字符串转换为C ++中的无符号整数.我的代码如下:
I'm trying to convert a hex string to an unsigned int in C++. My code looks like this:
string hex("FFFF0000");
UINT decimalValue;
sscanf(hex.c_str(), "%x", &decimalValue);
printf("\nstring=%s, decimalValue=%d",hex.c_str(),decimalValue);
结果是-65536.我通常不会做太多的C ++编程,因此将不胜感激.
The result is -65536 though. I don't typically do too much C++ programming, so any help would be appreciated.
谢谢, 杰夫
推荐答案
使用int用%u
而不是%d
这篇关于C ++十六进制字符串到unsigned int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文