我很新的C,我試圖理解這個代碼,但是有一些東西我不明白,比如參數Byte data[]
,我不明白是什麼傳遞給函數(Byte *) &i
。 我會很感激任何幫助,謝謝。C程序設計IEEE 754小數二進制轉換器
代碼:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
typedef unsigned char Byte;
void showsignal(char str[], Byte data[], int size) {
int i,j;
printf ("%s: ", str);
for (i = size-1; i> size-2; i--) {
for (j = 1; j > 0; j--) {
int bit = (data[i] >> j) & 1;
printf ("%d", bit);
}
}
printf ("n");
}
void showexponent(char str[], Byte data[], int size) {
int i,j;
printf ("%s: ", str);
for (i = size-2; i>size-3; i--) {
for (j = 7; j >= 0; j--) {
int bit = (data[i] >> j) & 1;
printf ("%d", bit);
}
}
printf ("n");
}
void showsignificand(char str[], Byte data[], int size) {
int i,j;
printf ("%s: ", str);
for (i = size-3; i>size-4 ; i--) {
for (j = 23; j > 0; j--) {
int bit = (data[i] >> j) & 1;
printf ("%d", bit);
}
}
printf ("n");
}
int main(int argc, char *argv[]) {
float f;
int i;
f = atof(argv[1]);
i = trunc(f);
if (f-i == 0) {
showsignal("sinal", (Byte *) &i, sizeof(i));
showexponent("expoente", (Byte *) &i, sizeof(i));
showsignificand("mantissa", (Byte *) &i, sizeof(i));
} else {
showsignal("sinal", (Byte *) &f, sizeof(f));
showexponent("expoente", (Byte *) &f, sizeof(f));
showsignificand("mantissa", (Byte *) &f, sizeof(f));
}
return 0;
}
請您能夠直接在問題的引擎收錄代碼? –