What is endianness? Describe the ways an integer is stored in memory.
Endianness is the process of ordering the addressable sub units such as words, bytes or bits in a longer word that is to store in an external memory. The typical ordering of bytes is with a 16 or 32 or 64 bits word. The usual contract is between most and least significant byte first, known as big-endian and little-endian.
A value in computer’s memory is represented as a binary number, which is a combination of 0’s and 1’s (bits – binary digits). The combination of 8 bits is called as a ‘byte’ (8 bits = 1 byte). Memory is measured in bytes and the data type ‘byte’, refers to a single byte of memory. The data type ‘short’ occupies 2 bytes (16 bits). For example, the byte 24 occupies 1 byte of memory space and ‘short’ 24 occupies 2 bytes, the ‘int’ occupies 4 bytes and the ‘long’ occupies 8 bytes. Each data type has varied range of values to represent.
The constant 24 of byte represents 00011000
The constant 24 of short represents 0000000000011000
The constant 24 of int represents 00000000000000000000000000011000
The constant 24 of long represents 0000000000000000000000000000000000000000000000000000000000011000.