Skip to content

Memory, Byte Order, Little Endian and Big Endian

When a computer wants to send a packet to the network, the computer software copies the packet into the memory, then the packet is copied from memory to the NIC. Similarly, when a computer wants to receive a packet from the network, the computer software copies the packet from the NIC into memory, then retrieves the packet from memory.

A CPU has a set of registers. The size of the register determines how much memory it can address at one time. For example,  a 64-bits CPU means that the processor registers can handle 64-bit chunks of memory at a time. Also, this number determines the number of addressable memory locations, i.e. a 64-bits CPU has 264 addressable memory locations.

There are three types of memory in a computer: Cache memory, Main memory (RAM) and Disk memory. For the sake of simplicity, we will confuse all types and talk about “memory” in general.

The memory contains memory cells. Each memory cell contains a “word”. The word can be 1, 2, or 4-byte long, depending on the computer architecture.

Each memory cell is indexed with a memory address. The memory address is the way to reach a certain word in memory. The first address is 0. The last address is 264- 1 if it is a 64-bit computer.

When the computer software wants to store data in the memory, the data is converted into binary then stored in memory. That’s because memory stores data only in binary numbers. But for simplicity and academic purposes, we assume that it also stores numbers in hexadecimal format.

The size of the data and the size of memory cells determine the number of cells to be used.

For example, if we have:

  • a cell size of 1 byte,
  • a word of two bytes (a multi byte word)

then the system software will write the data on two consecutive cells, which means it will write the multi byte word on two memory addresses: one low (address A) and one high (address A+1). But how does the software write it? Does it begin with the MSB or the LSB? This is defined by the computer Endianness

There are two ways to write multibyte words: Little Endian and Big Endian. In Little Endian, the LSB is written on the lower memory address and the MSB on the higher memory address (i.e. horizontally, LSB written on the left and MSB written on the right). In Big Endian, the MSB is written on the higher memory address and LSB on the lower memory address (i.e. horizontally, MSB written on the left and LSB written on the right). Big Endian is the way humans write numbers.

For more on memory in a computer system, refer to this awesome video made by Abelardo Pardo, a Senior Lecturer at the School of Electrical and Information Engineering at The University of Sydney:

You can also read this Wikipedia reference for big numbers.

Published inNetworking Basics

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

copyright 2020