Hey everyone....Im trying to learn about unions and Im finding it hard too grasp with the reference I have...Im trying to write this program that uses a union to combine a long int and a struct with four members...I first have to ask a user to enter a hex value in and the program is to display the user value in both hex and decimal...then using the structure members, display the user value one byte at a time in both hex and decimal..my question is that if I read in a long int(4bytes I hope) but it only takes in the first 4 hex values(2 bytes) and ignores everything before? I have very limited knowledge and have been playing/trying to understand union manipulations...and I could really use a boost to get me to where (and hopefully how) to read individual bytes(I can read the LSB in hex but not long int(%ld(right))...thanks for lookin...
* Program Description: This program asks the user to input an integer
* value in Hex and displays it in hex and decimal
* form.Then each byte of the structure is displayed
* in decimal form.
unsigned char byte1;
unsigned char byte2;
unsigned char byte3;
unsigned char byte4;
struct bytes complete;
char input = 'y';
while(input == 'Y' || input == 'y')
printf("please enter a hexvalue..(ie e34f2)");
printf("the value is:%ld\n",num.value);
printf("the lsb is %xH dec is ?\n",num.complete.byte1);
} /* End of Main */