C Programming
Computer Programming

C program to extract individual bytes from an unsigned int using union



Write a program in C to extract individual bytes from an unsigned int using union

\* C program to extract individual bytes from an unsigned int using union *\

# include < stdio.h >
# include < conio.h >
struct   tagname
{

unsigned int a ;
unsigned char s[4] ;

} ;

union tagname object ;
int   main( )
{

char i ;
object.a = 0xAABBCCDD ;
printf("\n Integer number: %ld, hex: %X\n", object.a, object.a ) ;
printf("\n Indivisual bytes: ") ;
for( i=3 ; i>=0 ; i-- )
      printf("%02X ",object.s[i]) ;

printf("\n") ;
return 0 ;

}

Output of Program :

Output of C program to extract individual bytes from an unsigned int using union