[英]converting hex to 64 bit bitset c++
我想在屏幕上输入最多16个十六进制字符的字符串,然后将字符串转换为bitset <64>
到目前为止,我已经管理了以下内容
string tempString;
unsigned int tempValue;
cout << "enter addr in hex : ";
cin >> tempString;
istringstream ost(tempString);
ost >> hex >> tempValue;
bitset<32> addr(tempValue);
cout << "addr = " << addr << endl;
效果很好,但是当我重复64位操作时,它失败了。 玩它似乎只对前32位失败!
bitset<64> wdata = 0;
if (rdnwr[0] == 0)
{
cout << "enter wdata in hex : ";
cin >> tempString;
istringstream ost1(tempString);
ost1 >> hex >> tempValue;
wdata = tempValue;
cout << "wdata = " << wdata << endl;
}
这与istringstream的最大大小有关吗? 还是我分配wdata的方式不同?
谢谢。
猜测中,您错过了将某些内容更改为64位(该位集,或者可能将int
更改为long long
)的想法。 但是,这是:
string tempString;
unsigned long long tempValue;
cout << "enter addr in hex : ";
cin >> tempString;
istringstream ost(tempString);
ost >> hex >> tempValue;
bitset<64> addr(tempValue);
cout << "addr = " << addr << endl;
...似乎可以工作,至少对我来说:
enter addr in hex : 0123456789abcdef
addr = 0000000100100011010001010110011110001001101010111100110111101111
[使用VC ++和MinGW进行测试,结果相同]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.