Skip to Content

Memory (RAM)

Introduction

Before I explain what is Memory (RAM), you need to understand how computers work in a very basic level. Computers process data in binary form, which is represented by bits (0s and 1s). These bits are grouped together to form bytes, and bytes are used represent various types of data such as integers, characters, and more complex data structures.

As a developer, you will often work with variables in your code. These variables need to be stored somewhere in the computer’s memory so that they can be accessed and manipulated during program execution. This is where RAM (Random Access Memory) comes into play.

What is RAM?

RAM stands for Random Access Memory, which is a type of computer memory that is used to store data that is actively being used or processed by the computer. RAM is volatile memory, meaning that it loses its contents when the computer is turned off.

Modern computers typically come with at least 8GB of RAM. The more RAM a computer has, the more data it can process simultaneously, which can lead to better performance. To put that into perspective:

  • 8GB of RAM = 8,589,934,592 bytes
    • 8 x 1024 (giga) x 1024 (mega) x 1024 (kilo) = 8,589,934,592 bytes
    • 8,589,934,592 bytes = 68,719,476,736 bits (8GB x 8 bits per byte)
    • 8GB of RAM can store approximately 2 billion integers (assuming each integer takes up 4 bytes).
      • Each integer takes 4 bytes, so 8,589,934,592 bytes / 4 bytes per integer = 2,147,483,648 integers.
  • 16GB of RAM = 17,179,869,184 bytes
    • 16 x 1024 (giga) x 1024 (mega) x 1024 (kilo) = 17,179,869,184 bytes
    • 17,179,869,184 bytes = 137,438,953,472 bits (16GB x 8 bits per byte)
    • 16GB of RAM can store approximately 4.3 billion integers (assuming each integer takes up 4 bytes).
      • Each integer takes 4 bytes, so 17,179,869,184 bytes / 4 bytes per integer = 4,294,967,296 integers.

Components of RAM

RAM can be considered as a contiguous block of data (memory is allocated to a process or file needing it), which means that it has two components:

  • value - the actual data being stored (e.g., an integer, character, etc.).
  • address - the location where the value is stored in memory and is used to access the value.

Binary Representation

Computers use binary representation to store and process data. In binary, all data is represented using only two symbols: 0 and 1. Each digit in a binary number is called a bit. For example, the decimal number 5 is represented in binary as 101.

When data is stored in RAM, it is stored as a series of bits. Each bit can be either 0 or 1, and multiple bits are grouped together to form larger data types, such as bytes (8 bits), words (16 bits), and double words (32 bits).

For example, the integer 5 can be represented in binary as follows:

  • Decimal: 5
  • Binary: 00000000 00000000 00000000 00000101 (32 bits)

Here is a table showing the binary representation of the first 10 decimal numbers in different bit sizes:

Decimal8-bit Binary16-bit Binary32-bit Binary
10000000100000000 0000000100000000 00000000 00000000 00000001
20000001000000000 0000001000000000 00000000 00000000 00000010
30000001100000000 0000001100000000 00000000 00000000 00000011
40000010000000000 0000010000000000 00000000 00000000 00000100
50000010100000000 0000010100000000 00000000 00000000 00000101
60000011000000000 0000011000000000 00000000 00000000 00000110
70000011100000000 0000011100000000 00000000 00000000 00000111
80000100000000000 0000100000000000 00000000 00000000 00001000
90000100100000000 0000100100000000 00000000 00000000 00001001
100000101000000000 0000101000000000 00000000 00000000 00001010

This binary representation is what is actually stored in RAM.

How Data is stored in RAM?

Store Array of Integers in RAM

Let’s say we have an array of integers. For example we have [1, 2, 3]. But how can we store all these integers in the RAM, as computers only understand bits 0 or 1.

So the integer will be converted into bits like for example,

  • 1 can be represented as 00000001
  • 2 as 00000010
  • 3 as 00000011.

Then we can only put that into RAM.

Store Array of Characters in RAM

Let’s say we have an array of characters. For example we have ['a', 'b', 'c']. But how can we store all these characters in the RAM, as computers only understand bits 0 or 1. Similar to integers, we need to convert the characters into bits.

So the character will be converted into bits like for example,

  • ‘a’ can be represented as 01100001 (decimal 97)
  • ‘b’ as 01100010 (decimal 98)
  • ‘c’ as 01100011. (decimal 99)

Do take note that, the address is incrementing by 1 because each character takes 1 byte (8 bits) of memory space.

RAM Visualization

Interactive demonstration of RAM operations with addresses, values, and bit representation.

Memory Controller

The reason below that each memory cell is 1 byte (8 bits) is because it only hold values from 0-255 (2^8 - 1), not full 32-bit integers.

0-255 range

Leave empty for random value. Click a cell to select it, then use Write to Selected Cell.

Memory Array (8 Cells)
Read Operation
Write Operation
Data Present
Empty Cell
Last updated on