Endianness

Learn about the little-endian and big-endian byte orders used by computers.

Introduction

We know that different data types have different sizes and that we typically measure that size in bytes.

For example, an integer has a size of 4 bytes. Therefore, to represent the integer in memory, we use a sequence of 4 bytes or 32 bits. Let’s say we want to represent the integer 2022. The binary representation of 2022 is 11111100110.

We need 11 bits to represent it, but we know an integer takes 32 bits, so to extend 11 bits to 32, we add 0s as padding. Therefore, the full representation is 00000000000000000000011111100110. Or, if we want to see the individual bytes, we can add some spacing after each group of 8 bits: 00000000 00000000 00000111 11100110.

Let’s create a memory drawing and represent the bytes:

Get hands-on with 1200+ tech skills courses.