J
junky_fellow
Hi guys,
I need to convert a big endian integer to little endian integer.
(the integer is 4 bytes in size on my implementation). I came up with
the following code. I need your comments on this. Please suggest any
improvements that can be done.
#include <stdio.h>
int main(void)
{
int big = 0x12345678;
int little;
char *big_ptr = (char *)&big;
char *little_ptr = (char *)&little;
little_ptr[0] = big_ptr[3];
little_ptr[1] = big_ptr[2];
little_ptr[2] = big_ptr[1];
little_ptr[3] = big_ptr[0];
printf("big = 0x%x little = 0x%x\n",big,little);
}
I need to convert a big endian integer to little endian integer.
(the integer is 4 bytes in size on my implementation). I came up with
the following code. I need your comments on this. Please suggest any
improvements that can be done.
#include <stdio.h>
int main(void)
{
int big = 0x12345678;
int little;
char *big_ptr = (char *)&big;
char *little_ptr = (char *)&little;
little_ptr[0] = big_ptr[3];
little_ptr[1] = big_ptr[2];
little_ptr[2] = big_ptr[1];
little_ptr[3] = big_ptr[0];
printf("big = 0x%x little = 0x%x\n",big,little);
}