Big-endian and Little-endian
- Java follows Big-endian byte order.
- Big-endian and little-endian are terms that show the order in which a sequence of bytes are stored in computer memory.
Big-endian is an order in which the “big end” or in other words the most significant value in the sequence is stored first (at the lowest storage address).
Little-endian is an order in which the “little end” (least significant value in the sequence) is stored first or at a higher storage address.
- For example, if there are two storage addresses 1000 and 1001 and one has to store the hexadecimal number 4F52, then the most significant bit (4F) will be stored at address 1000 and 52 will be stored at address 1001.
- In a little-endian system, the number 4F52 would be stored as 524F
- i,e 52 at address 1000 and 4F at address 1001.
- (52 at address 1000, 4F at 1001).
- IBM’s 370 mainframes as well as most RISC-based computers and Motorola microprocessors use the big-endian
- TCP/IP also uses the big-endian approach.
- For those who use languages that read from left-to-right, this seems a natural way to present the numbers. Big-endian can be thought of as storing something in forward fashion, just as we read.
- On the other hand, Intel processors (CPUs) and DEC Alphas are little-endian.
- An argument for little-endian order is that as you increase a numeric value, you may need to add digits to the left
- Thus, an addition of two numbers often requires moving all the digits of a big-endian ordered number in storage, moving everything to the right.
- In a number stored in little-endian fashion, the least significant bytes can stay where they are and new digits are added to the right at a higher address.
- This means that some computer operations may be simpler and faster to perform.
- Language compilers such as Java or FORTRAN need to know the way the object code they develop is going to be stored.
- Converters are used to change one kind of endian to the other when necessary.