CS 101 › Lesson 3 of 8

Binary & Number Systems

Lesson 3 · OKSTEM College · Associate of Science in Computer Science

Binary & Number Systems

Computers store everything — numbers, text, images, code — as sequences of 0s and 1s called bits. Understanding binary is fundamental to understanding computation.

Positional Number Systems

In decimal (base-10), each position is a power of 10. In binary (base-2), each position is a power of 2:

// Decimal: 42 4×10¹ + 2×10⁰ = 40 + 2 = 42 // Binary: 101010 1×2⁵ + 0×2⁴ + 1×2³ + 0×2² + 1×2¹ + 0×2⁰ = 32 + 0 + 8 + 0 + 2 + 0 = 42

Hexadecimal (Base-16)

Programmers use hex as a compact notation for binary. Each hex digit represents exactly 4 bits:

DecimalBinaryHex
0–90000–10010–9
101010A
151111F
25511111111FF

Memory addresses, color codes (#FF6600), and file offsets are all written in hexadecimal.

Integer Representation

Unsigned Integers

An n-bit unsigned integer can represent 0 to 2ⁿ−1. An 8-bit byte: 0–255. A 32-bit int: 0–4,294,967,295.

Two's Complement (Signed Integers)

To represent negative numbers, computers use two's complement: flip all bits, add 1. This allows the same addition hardware to handle both positive and negative numbers.

// 8-bit two's complement +5 = 00000101 -5 → flip = 11111010, add 1 = 11111011 // Verify: 5 + (−5) should = 0 00000101 + 11111011 ────────── 00000000 ✓ (carry discarded)

Lab — Number Base Converter

42

Knowledge Check

How many values can an 8-bit unsigned integer represent?

What is the decimal value of binary 1101?

Hexadecimal is base-16. The hex digit 'A' equals decimal

Two's complement is used to represent

0xFF in decimal is

← PreviousNext →