C++将8位位集转换为无符号长,VS 2010-不工作
C++ convert 8 bit bitset to unsigned long, VS 2010 - not working
下面的代码首先通过两次,然后第三次转换到ulong失败,给我一个0XCF而不是0xF3。知道问题出在哪里吗??似乎是VS 2010 to_long中的一个错误。二进制"11110011"应转换为十六进制F3!以下是在VS2010下运行调试时的结果。
第一时间bc_bit_char b'11000011'转换为k=x'000000c3';第二次:bc_bit_char b'00111100'转换为k=x'0000003c'第三次:bc_bit_char b'11110011'转换为k=x'000000cf'错误!s/b x 000000f3'
std::bitset<8> bc_bit_char (00000000);
unsigned char bc_char=' ', bc_convert_char=' ';
unsigned long k=0, bc_rows=0;
k = bc_bit_char.to_ulong(); // convert 8 bits to long integer with same bits
bc_convert_char = static_cast<unsigned char> (k); // convert long integer to unsigned
对于哪个位最重要和哪个位最不重要存在混淆。在您提供的二进制常量中,最左边的位是最低有效位0。在to_long
提供的十六进制值中,最左边的比特是最高有效的比特7。如果你颠倒其中一个,那么它们将是相等的。
相关文章:
- VisualStudio 2015 链接器查找 VS 2010 库
- 代码 c++ VS 2010 中的 LPCWSTR 到字符串转换问题
- (视觉-)C++ 字符串文本的模板类型推断 - VS 2010 与 VS 2017
- 转换 VS 2010 和 2015 之间的差异
- 应用程序无法使用 libcurl C++ Windows 7 VS 2010 启动 (0xc0150002)
- VS 2010 c++ Express 无法链接 recv() 和 send()
- 从IBM VisualAge C++3.6.5迁移到VS 2010
- 无法在VS 2010中编译VCG库
- 如何在我的 VS 2010 项目中包含 SDL 库
- 在VS 2010中链接WASAPI
- Windows 7 VS 2010 的时间规范转换
- 我的计算机中缺少 SDL.dll - VS 2010
- VS 2010 Qt 加载项中的链接错误
- VS 2010中的C++调试访问冲突
- 如何在VS 2010上安装BASS音频库
- 在VS 2010上使用boost::interprocess生成代码问题
- Visual Studio 2013 在使用 VS 2010 平台工具集时找不到头文件
- VS 2010 : 2 个重载具有类似的转换
- MFC C++VS 2010:编辑框只接受字母、退格和空格
- 为什么在VS 2010 C++中,我的程序在调试器中运行良好时会崩溃,但在没有调试器的情况下运行时会崩溃