Deep dive: how computers really store data.
From individual bits, signed integers and IEEE 754 floats, to bitwise operations, data types in
memory, and text encoding β all interactive.
π’ Bit Playground β All Bases Live
Bit width:
Mode:
Binary (Base 2)
Octal (Base 8)
Decimal (Base 10)
Hexadecimal (Base 16)
Signed interpretation: MSB (leftmost bit) = 0 β positive
π Step-by-step: Decimal β Binary
Quick examples
Why different bases?
Computers work in binary (base 2) because circuits are either on or off.
Octal and Hex are shorthand β each hex digit = 4 bits, so programmers use hex to read
binary more easily.
Two's Complement (Signed)
To store negative numbers, computers use two's complement: flip all
bits, then add 1. The most significant bit (MSB) acts as the sign bit:
0=positive, 1=negative.
β1 in 8-bit = 11111111
β128 in 8-bit = 10000000
127 max positive = 01111111
Range reference (8-bit)
Type
Min
Max
Unsigned
0
255
Signed
-128
127
Overflow demo
In 8-bit unsigned: 255 + 1 = 0 (wraps around). In 8-bit signed: 127 + 1 = -128!
π¦ Data Types & Memory Layout
Click a type to explore its size, range, and bit layout
RAM Memory Layout β variables side by side:
Why different types?
Using a bool for true/false wastes space if you used int. Using
float lets you store decimals. Choosing the right type saves memory and
speeds up programs.
IEEE 754 Float (32-bit)
Floats split 32 bits into 3 fields:
1 bit: Sign8 bits: Exponent23 bits: Mantissa
Value = (β1)sign Γ 2expβ127 Γ 1.mantissa
Struct layout example
struct Example {
char c; // 1
byte β addr 0x00
int i; // 4
bytes β addr 0x04 (aligned)
double d; // 8
bytes β addr 0x08
} // total: 16 bytes with padding
βοΈ Bitwise Operations Lab
Operate on individual bits β the foundation of computer logic
What are bitwise ops?
Bitwise operators work bit by bit on two numbers, comparing each bit
position using logic gate rules.
AND
Real-world uses
πAND: check/clear specific bits
(bitmasks)
πOR: set specific bits to 1
πXOR: toggle bits, simple encryption
β¬ Left shift: fast multiply by 2
β‘Right shift: fast divide by 2
π Text Encoding β ASCII, UTF-8 & Unicode
Encoding:
How this string lives in memory:
+ null terminator 0x00 at the end
(C-style strings)
π
ASCII uses 7 bits (128 chars). UTF-8 is
backward-compatible but uses 1β4 bytes per character β emojis like π need 4
bytes!