#include <stdio.h>
typedef struct BIT {
unsigned a : 8;
unsigned b : 8;
unsigned c : 8;
unsigned d : 8;
} BIT_8;
int main(int argc, char const* argv[])
{
char tmp = 0;
int r[4][8] = {
{0}};
float val = 0.0;
scanf("%f", &val);
BIT_8 *Bp = (BIT_8 *)&val;
printf("%d %d %d %d\n", (int)(Bp -> a ), (int)(Bp -> b ), \
(int)(Bp -> c ), (int)(Bp -> d ));
for (int i = 0; i < 4; i++) {
if(i==0)
tmp = (char) Bp -> a;
if(i==1)
tmp = (char) Bp -> b;
if(i==2)
tmp = (char) Bp -> c;
if(i==3)
tmp = (char) Bp -> d;
for (int j = 0; j < 8; j++) {
if(tmp < 0)
r[i][j] = 1;
else
r[i][j] = 0;
tmp <<= 1;
}
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 8; j++) {
printf("%d", r[i][j]);
}
printf("\t");
}
return 0;
}
转载于:https://my.oschina.net/dengwo/blog/665772
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/109057.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...