union MyUnion{ int myInt; char myChar[sizeof(int)]; }; void main() { MyUnion m; m.myInt = 0x01020304; printf("value :%d\n",m.myChar[0]); // -> value : 4 printf("value :%d\n",m.myChar[1]); // -> value : 3 printf("value :%d\n",m.myChar[2]); // -> value : 2 printf("value :%d\n",m.myChar[3]); // -> value : 1 } -----Original Message----- From: linux-c-programming-owner@xxxxxxxxxxxxxxx [mailto:linux-c-programming-owner@xxxxxxxxxxxxxxx] On Behalf Of ratheesh k Sent: Monday, December 20, 2010 2:10 PM To: linux-c-programming@xxxxxxxxxxxxxxx Subject: union to get parts of integer typedef struct { char parts[4]; } node ; int i=0x12345678 ((node *)&i)->parts[0]; ((node *)&i)->parts[1]; ((node *)&i)->parts[2]; ((node *)&i)->parts[3]; Is there any mechanism to split into bytes using the power of union ? -Ratheesh -- To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html