代码如下:
#include <stdio.h>
#include <conio.h>
void Show_Byte(unsigned char ch)
{
char buffer[8];
unsigned char mask = 1;
for (size_t index = sizeof(buffer); index > 0; --index)
{
buffer[index - 1] = ((ch & mask) == mask) + '0';
mask <<= 1;
}
for (size_t index = 0; index < sizeof(buffer); ++index)
{
putchar(buffer[index]);
}
}
int main()
{
unsigned char* p;
int a = 1000;
p = (unsigned char*)&a;
for (size_t index = 0; index < sizeof(a); ++index)
{
Show_Byte(*p++);
putchar(' ');
}
putchar('\n');
double b = 1000;
p = (unsigned char*)&b;
for (size_t index = 0; index < sizeof(b); ++index)
{
Show_Byte(*p++);
putchar(' ');
}
putchar('\n');
float c = 1000;
p = (unsigned char*)&c;
for (size_t index = 0; index < sizeof(c); ++index)
{
Show_Byte(*p++);
putchar(' ');
}
putchar('\n');
_getch();
return 0;
}