#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <climits>
using namespace std;
void ConvertToBin1(unsigned int n);
void ConvertToBin2(unsigned int n);
int main()
{
ConvertToBin1(101);
cout<<endl;
ConvertToBin2(101);
}
void ConvertToBin1(unsigned int n)
{
if(n != 0)
{
ConvertToBin1(n / 2);
printf("%d",n % 2);
}
}
void ConvertToBin2(unsigned int n)
{
int bits = sizeof(int) * CHAR_BIT;
int mask = 1 << (bits-1);
for(int i = 1; i <= bits; i++)
{
putchar( ((n & mask)) == 0 ? '0' : '1');
n <<= 1;
}
}
十进制转换二进制
最新推荐文章于 2022-07-11 17:00:51 发布