/******************************
作者:cncoderalex
博客:http://blog.csdn.net/cncoderalex
*******************************/
#include<iostream>
using namespace std;
template <typename T>
void PrintBinary(T value)
{
int BytesCount = sizeof(T);
unsigned long long Bit = 1;
string str;
for (int i = 0; i < BytesCount * 8; i++)
{
if (value & Bit)
{
str.append("1");
}
else
{
str.append("0");
}
Bit <<= 1;
}
int len = str.length();
for (int i = len - 1; i >= 0; i--)
{
printf("%c", str[i]);
}
printf("\n");
}
int main()
{
printf("http://blog.csdn.net/cncoderalex");
printf("\n");
int a = -1;
unsigned char b = a;
int c = b;
char d = a;
int e = b;
short f = a;
int g = b;
PrintBinary(a);
PrintBinary(b);
PrintBinary(c);
PrintBinary(d);
PrintBinary(e);
PrintBinary(f);
PrintBinary(g);
system("pause");
return 0;
}
打印二进制位
最新推荐文章于 2021-05-18 11:31:18 发布