write a program to convert an integer in little-endian format to big-endian...
please reply ASAp
write a program to convert an integer in little-endian format to big-endian...
please reply ASAp
Determine the size of an integer using sizeof(int) so you know how many bits to shift, and then use right shift and AND operations to get the individual bytes. Then just add them upp to get the reversed integer.
Done.Code:#include <arpa/inet.h> int main() { int littleEndian = 5; int bigEndian = htonl( littleEndian ); return 0; }
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
It's probably for a homework assignment, so I doubt they're allowed to use POSIX functions.