[英]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.