MIPI_BaseC_WebinarFRTK/23_Seminar10/01_union_p7.c

23 lines
447 B
C
Raw Normal View History

2024-11-13 09:22:28 +03:00
#include <stdio.h>
#include <inttypes.h>
union intbytes {
uint32_t number;
uint8_t bytes[4];
} d;
int main()
{
d.number = 0x12345678;
printf ("Number %x",d.number);
printf(" in memory is: %x %x %x %x\n", d.bytes[0],
d.bytes[1], d.bytes[2], d.bytes[3]);
// Number 12345678 in memory is: 78 56 34 12
uint32_t number = 0x12345678;
printf(" in memory is: %x\n",(number >> 8)&0xff);
return 0;
}