
枫叶飘零为您分享以下优质知识
整数转换为二进制输出的方法根据编程语言和需求有所不同,以下是常见方法及示例:
一、C/C++中的转换方法
通过不断取余和右移操作,将余数按位存储后倒序输出。 ```cpp
include
include
using namespace std;
void output_Z(LL a) {
vector vct;
if (a == 0) {
cout 0) {
vct.push_back(a % 2);
a /= 2;
}
for (int i = vct.size() - 1; i >
= 0; i--) {
cout = 0; i--) {
vct[i] = (n >
>
i) & 1;
}
for (int i = 0; i < 32; i++) {
cout