belongs to collection: C Structure and Union programs
#include<stdio.h> union tagname { unsigned int a; unsigned char s[4]; }; union tagname object; int main() { char i; //for loop counter //assign an integer number object.a=0xAABBCCDD; printf("Integer number: %ld, hex: %X\n",object.a,object.a); printf("Indivisual bytes: "); for(i=3;i>=0;i--) printf("%02X ",object.s[i]); printf("\n"); return 0; }
Output
Integer number: 2864434397, hex: AABBCCDD Indivisual bytes: AA BB CC DD
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
C union program to extract individual bytes from an unsigned int
Output
need an explanation for this answer? contact us directly to get an explanation for this answer