CS 211: Computer Organization › Lesson 1 of 10

Data Representation & Number Systems

Lesson 1 · OKSTEM College · AS Computer Science

Why Computers Use Binary

Every value inside a computer — numbers, letters, images, code — is ultimately stored as binary: a sequence of 1s and 0s. Hardware uses two voltage levels (high/low) to represent these bits because two-state systems are extremely reliable and cheap to manufacture.

A single binary digit is a bit. Eight bits form a byte. From bytes we build kilobytes (210), megabytes (220), gigabytes (230), and so on.

Converting Between Bases

Binary → Decimal

Each bit position is a power of 2, starting at 20 on the right.

Worked Example — 10112 to Decimal

Write out the bit positions: bit 3, bit 2, bit 1, bit 0 (right to left).
Multiply each bit by its power of 2: 1×8 + 0×4 + 1×2 + 1×1
Add the results: 8 + 0 + 2 + 1 = 11

Decimal → Binary (Repeated Division)

Worked Example — 45 to Binary

45 ÷ 2 = 22 remainder 1
22 ÷ 2 = 11 remainder 0
11 ÷ 2 = 5 remainder 1
5 ÷ 2 = 2 remainder 1
2 ÷ 2 = 1 remainder 0
1 ÷ 2 = 0 remainder 1 ← stop when quotient = 0
Read remainders bottom to top: 1011012. Verify: 32+8+4+1 = 45 ✓

Hexadecimal

Hex (base-16) compresses binary: each hex digit maps to exactly 4 bits. Digits 0–9 then A=10, B=11, C=12, D=13, E=14, F=15.

HexBinaryDecimal
000000
910019
A101010
F111115

0x2F = 0010 11112 = 2×16 + 15 = 47

Signed Numbers: Two's Complement

To represent negative integers, computers use two's complement. For an n-bit number, the most-significant bit (MSB) has a weight of −2n−1 instead of +2n−1.

Worked Example — Negate 5 in 8-bit Two's Complement

Write +5 in binary: 0000 0101
Flip all bits (one's complement): 1111 1010
Add 1: 1111 1010 + 1 = 1111 1011
Verify: −128 + 64 + 32 + 16 + 8 + 0 + 2 + 1 = −5 ✓

Range for 8-bit signed: −128 to +127. The bit pattern 1000 0000 = −128 (no positive counterpart — this is why overflow matters).

Practice Problems

Problem 1 — Binary to Decimal

Convert 1101 01102 to decimal. Show each step.

Step 1: List bit positions 7 down to 0 and their powers of 2: 128, 64, 32, 16, 8, 4, 2, 1 Which bits are 1? Positions 7,6,4,2,1
Step 2: Multiply each 1-bit by its power: 128 + 64 + 16 + 4 + 2 Positions 7,6,4,2,1 → 128+64+16+4+2
Step 3: Add them up.
128 + 64 + 16 + 4 + 2 = 214

Problem 2 — Decimal to Hex

Convert 255 to hexadecimal.

Step 1: 255 ÷ 16 = 15 remainder 15 → digit = F
Step 2: 15 ÷ 16 = 0 remainder 15 → digit = F (stop)
Step 3: Read remainders bottom to top.
255 = 0xFF — all ones in 8-bit binary (1111 1111).

Problem 3 — Two's Complement Range

A 16-bit signed integer: what is the most negative value it can store?

−215 = −32,768. The bit pattern is 1000 0000 0000 0000.

🔬 Number Base Converter Lab

42

Knowledge Check

What is 1010 1010₂ in decimal?

Not quite. Count the bit positions: the 1-bits are at positions 7,5,3,1 (128+32+8+2).
Correct! 128+32+8+2 = 170.
Close — you may have missed one bit. Remember to include 2¹=2.
255 = 1111 1111₂ — all bits set. Here only alternating bits are set.
📖 Quick Recap

When reading binary, list all bit positions where the digit is 1, then sum their powers of 2. For 1010 1010: positions 7,5,3,1 → 128+32+8+2 = 170.

📖 Quick Recap

It's easy to miss the low-order bits. Always write out all 8 positions and check each one: 1×128 + 0×64 + 1×32 + 0×16 + 1×8 + 0×4 + 1×2 + 0×1 = 170.

📖 Quick Recap

255 = 1111 1111. In this number, alternating bits are 0, so the total is lower. Re-check which positions have a 1.

To negate a two's complement number you:

Only flipping the MSB changes the sign but leaves the magnitude wrong.
Correct — that is the two's complement negation rule.
Adding 1 alone increments the number; it doesn't negate it.
Division isn't how hardware negates — bit manipulation is used instead.
📖 Quick Recap

Flipping only the MSB is the sign-magnitude approach, not two's complement. Two's complement: flip ALL bits, then add 1. This ensures addition still works correctly in hardware.

📖 Quick Recap

Adding 1 just gives you n+1, not −n. The full process is: invert every bit, then add 1.

📖 Quick Recap

Hardware negation is a bit operation, not arithmetic division. Flip all bits, add 1 — then the adder circuits can handle subtraction as addition of a negative.

0xFF in decimal is:

256 = 0x100. 0xFF is one less than 256.
Correct! F=15, so 0xFF = 15×16 + 15 = 255.
240 = 0xF0 (only the upper nibble). 0xFF has F in both nibbles.
128 = 0x80 (just the MSB set in 8 bits).
📖 Quick Recap

0x100 = 1×256 = 256. 0xFF = 15×16 + 15 = 255. Remember: F = 15, so FF = 15×16 + 15.

📖 Quick Recap

0xF0 = 15×16 + 0 = 240. But 0xFF = 15×16 + 15 = 240 + 15 = 255.

📖 Quick Recap

0x80 = 8×16 + 0 = 128. 0xFF is much larger — all 8 bits set = 255.

An 8-bit unsigned integer can represent values from 0 to:

128 = 2⁷. The 8-bit range is 2⁸ − 1 = 255.
Correct — 2⁸ − 1 = 255.
256 is the count of values (2⁸), but the maximum VALUE is 255 (since we start at 0).
512 would require 9 bits (2⁹ = 512 patterns, max value 511).
📖 Quick Recap

2⁷=128 is the range for 7 bits. For 8 bits: 2⁸ = 256 distinct values → 0 to 255.

📖 Quick Recap

There are 2⁸=256 distinct patterns, but they represent 0 through 255. Maximum value = 256−1 = 255.

📖 Quick Recap

9-bit range: 0–511. 8-bit unsigned: 0–255.

Hexadecimal is useful in computing primarily because:

Hex has 16 symbols vs decimal's 10 — more, not fewer.
Correct — 4 bits → 16 possible values → 1 hex digit. This makes binary readable.
CPUs operate in binary internally regardless of how we write numbers.
Signed representation (two's complement) is independent of the base we write in.
📖 Quick Recap

Hex has digits 0–9 plus A–F (16 total). The benefit isn't fewer symbols but a cleaner relationship to binary.

📖 Quick Recap

All CPU arithmetic is binary. Hex is just a human-readable shorthand — it doesn't change what the CPU does.

📖 Quick Recap

Two's complement works the same whether you write numbers in decimal, hex, or binary. Hex's advantage is compact binary representation.

Next →