如何把一个十进制数转化为一个二进制数

起因

Miqa在改愤怒的小鸟,WA了两个点,尝试画图未遂,于是开调,但是想直观的看到二进制数,所以有了这个工具。

#include<bits/stdc++.h>
using namespace std;
inline void twice(long long x)
{
	stack<int>num;
	while(x!=0)
	{
		if(x&1) num.push(1);
		else num.push(0);
		x>>=1;
	}
	while(!num.empty())
	{
		printf("%d",num.top());
		num.pop();
	}
	printf("\n");
}
int main()
{
	long long a;
	while(1)
	{
		scanf("%lld",&a);
		twice(a);
	}
}

效果非常的好。
image

posted @ 2024-04-05 16:26  一位很会的教授er~  阅读(27)  评论(0编辑  收藏  举报