How Computers Work

Lesson 6 of 7

Binary Basics

Master the language of 1s and 0s and learn how computers represent numbers, letters, and pixels with switches.

🟡 Intermediate 80 XP

Learn it

Inside a computer are billions of microscopic electronic switches called transistors. A switch can only ever be in one of two states: ON or OFF.

Because switches only have two states, computers use the Binary number system (base-2), which uses only two digits: 1 (ON) and 0 (OFF).

A single 1 or 0 is called a BIT. When you group 8 bits together, you get a BYTE! Using bytes, computers can represent numbers, text letters, colours, and music.

Key terms

Bit
The smallest unit of data in computing; a binary digit that holds either a 0 or a 1.
Byte
A group of 8 bits capable of representing 256 unique values (0 to 255).
Transistor
A microscopic semiconductor switch that controls the flow of electrical current to represent binary states.
ASCII
American Standard Code for Information Interchange; a character-encoding standard that maps numbers to text characters.

Converting Binary to Denary (Decimal)

Learn how to convert the 8-bit binary byte 00101010 into a standard base-10 number.

  1. 11. Write Place Values: Place values for an 8-bit byte are: 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1.
  2. 22. Align the Bits: Write the binary bits underneath: 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0.
  3. 33. Add Active Values: Sum the place values that have a 1: 32 + 8 + 2 = 42.
  4. 44. Verify the Result: Binary 00101010 equals decimal 42! In ASCII, 42 represents the asterisk character (*).

Converting Text to Binary in Python

python# Convert each character of a string into its 8-bit binary representation
word = 'CODE'

for char in word:
    ascii_code = ord(char)          # Get numeric ASCII decimal
    binary_repr = f'{ascii_code:08b}' # Format as 8-bit binary string
    print(f'Char: {char} | ASCII: {ascii_code:3d} | Binary: {binary_repr}')

This script uses Python's ord() function and string formatting to show the direct link between human letters, ASCII codes, and 8-bit binary strings.

Try it

Complete the Python code to convert the binary string '00001101' (decimal 13) into an integer by specifying base 2.

binary_string = '00001101'
decimal_value = int(binary_string, ______)
print('Decimal result:', decimal_value)

Challenge

Calculate the binary representation of the decimal number 155 using an 8-bit byte.

Pick whichever way suits you — every mode earns the same bonus XP.

Write at least 40 more characters to submit.

Mark your own work

Guided walkthrough — 0/5 clues revealed

  1. Clue 1 locked — reveal it only if you get stuck.
  2. Clue 2 locked — reveal it only if you get stuck.
  3. Clue 3 locked — reveal it only if you get stuck.
  4. Clue 4 locked — reveal it only if you get stuck.
  5. Clue 5 locked — reveal it only if you get stuck.

Each clue costs 4 XP (never below 20 XP). You'd earn 40 XP right now.

Extension: Explain how hexadecimal (base-16) is used as a shorthand for binary and why one hex digit represents exactly 4 bits (a nibble).

Quiz time

Question 1 of 4Score 0

How many bits are in a single standard byte?