- #1
sunmaz94
- 42
- 0
Homework Statement
Write a C program that converts a 32-bit integer from little to big endian.
Homework Equations
None.
The Attempt at a Solution
Code:
return (((num&0x000000FF)<<24) + ((num&0xFF000000)>>24)) + ((num&0x0000FF00)<<8) + ((num&0x00FF0000)>>8);
This works for small numbers but fails when they get large. Everything is stores in unsigned long ints.
Any idea as to what is wrong?
Thanks in advance.