将十六进制转换为64位的位集c++
converting hex to 64 bit bitset c++
我想在屏幕上输入一个最多16个十六进制字符的字符串,然后将该字符串转换为位集<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;
}
这与分发流的最大大小有关吗?或者我分配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测试,结果相同】
相关文章:
- 将应用程序从32位移植到64位时出现问题
- 64位机器上的C++内存对齐
- qmake:检测目标位宽(32 位或 64 位)
- 如何在 64 位 vb.net Windows 应用程序中引用 32 位 dll
- Qt 5.11.2 (Clang 8.0 (Apple), 64 位), 找不到 QJSEngine 文件
- 在 64 位边界上对齐C++结构数组?
- 如何为字符串生成唯一但一致的 N 位哈希(小于 64 位)?
- 在 64 位的 c++ 中运行 mstest 测试
- 在两个线程上读/写 64 位,无互斥/锁定/原子
- 浮点数为 32 位和 64 位二进制表示形式
- 是否有 64 位等效于 GetLastInputInfo / LASTINPUTINFO?
- 所有可能的链接生成器与64位密钥
- WinAPI C++如何从 64 位应用程序加载资源
- 在 c++ 中输出 64 位整数
- 使用192/256位整数求和无符号64位整数向量的点积的最快方法
- 如何在 64 位平台上计算 32 位哈希C++?
- 使用 SysNative 在 Visual Studio 中创建 64 位应用程序
- 在 64 位整数内旋转(90°)位矩阵(最多 8x8 位)
- 64 位进程中的 AnyCPU C# DLL 无法引用 64 位C++ DLL(给出错误:无法加载文件或程序集)
- 将代码从 32 位迁移到 64 位时出现问题 Visual Studio 2010