I’m working on a java question and need a sample draft to help me study.
The goal is to convert a 32-bit integer from Little Endian (Java, iPhone, Xbox) to Big Endian (Intel, TCP, IPv6) encoding, and also to other possible encodings as well.
In Little Endian encoding the first byte contains the most significant bits, and bytes 2, 3, and 4 decrease in significance. In Big Endian encoding the first byte contains the least significant bits, and bytes 2, 3 and 4 increase in significance. Thus, to move from Little Endian to Big Endian the byte shuffling is as follows:
Byte 1 -> Byte 4
Byte 2 -> Byte 3
Byte 3 -> Byte 2
Byte 4 -> Byte 1
We could of course shuffle the four bytes into a different order (e.g. Byte 3, Byte 4, Byte 1, Byte 2).
Please take in an integer encoded in Little Endian, and shuffle its bytes using bit manipulation operators and put them into the specified order.
Use user input please
state what programming language you used (java is preferred)