You are on page 1of 1

#?include?<stdio.

h>
main()
{
//bagian union 1
struct info_byte
{
unsigned char buf[4];
};
union test
{
struct info_byte byte;
float number;
}test;
//bagian union 2
struct info_byte2
{
unsigned char buf2[4];
};
union test2
{
struct info_byte2 byte2;
float number2;
}test2;
printf("Masukkan Bilangan Yang akan ditransfer = ");
scanf("%f",&test.number);
for(int i=0;i<4;i++)
{
printf("Isine Byte union1 ke %d iku %02x\n",i,test.byte.buf[i]);
}
//transfer byte
for(int i=0;i<=3;i++)
{
test2.byte2.buf2[i] = test.byte.buf[i]; //transfer satu2 per byte array
}
printf("hasil tranfer byte = ");
printf("%f\n",test2.number2);
for(int i=0;i<4;i++)
{
printf("Isine Byte union2 ke %d iku %02x\n",i,test2.byte2.buf2[i]);
}
}
Foto Muh Khoirul.

You might also like