Convert integer to binary and store it in an integer array of specified size:c++(将整数转换为二进制并存储在指定大小的整数数组中:c++)
问题描述
我想将整数转换为二进制字符串,然后将整数字符串的每一位存储到给定大小的整数数组的元素中.我确信输入整数的二进制表达式不会超过指定数组的大小.如何在 C++ 中做到这一点?
I want to convert an integer to binary string and then store each bit of the integer string to an element of a integer array of a given size. I am sure that the input integer's binary expression won't exceed the size of the array specified. How to do this in c++?
推荐答案
伪代码:
int value = ???? // assuming a 32 bit int
int i;
for (i = 0; i < 32; ++i) {
array[i] = (value >> i) & 1;
}
这篇关于将整数转换为二进制并存储在指定大小的整数数组中:c++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将整数转换为二进制并存储在指定大小的整数数组中:c++


- 从父 CMakeLists.txt 覆盖 CMake 中的默认选项(...)值 2021-01-01
- 如何提取 __VA_ARGS__? 2022-01-01
- XML Schema 到 C++ 类 2022-01-01
- 将 hdc 内容复制到位图 2022-09-04
- 哪个更快:if (bool) 或 if(int)? 2022-01-01
- 将函数的返回值分配给引用 C++? 2022-01-01
- GDB 不显示函数名 2022-01-01
- OpenGL 对象的 RAII 包装器 2021-01-01
- 使用 __stdcall & 调用 DLLVS2013 中的 GetProcAddress() 2021-01-01
- DoEvents 等效于 C++? 2021-01-01