Level 0 · Module 1

Binary numbers

Read and write base-two numbers using place values.

Difficulty
beginner
Time
8 min read
Prerequisites
Bits and bytes
Reading progress0% read

Not completed

By the end, you can

  • Identify binary place values.
  • Convert small binary values to decimal.
  • Convert a small decimal value to binary.

Summary

Binary is a way to write numbers using only 0 and 1. Each position stands for a power of two, so 10110₂ means 16 + 4 + 2, which is decimal 22.

Introduction

You already use place values in decimal: the digits in 347 mean three hundreds, four tens, and seven ones. Binary follows the same idea, but its places are ones, twos, fours, eights, and so on.

Explanation

Write the place values from right to left: 1, 2, 4, 8, 16, .... A 1 means “include this value”; a 0 means “do not include it.” To turn a decimal number into binary, first choose the largest place value that does not exceed the number. Subtract it, then repeat with smaller places.

Real-world example

Feature flags

A compact settings value can use one bit for each option. The pattern 101 can mean the first and third options are on while the second is off.

Read every column

Interactive exploration

Binary number

Step 1 of 8

00010110= 22
Read the 128 place. This bit contributes zero to the total.

To turn 22 into binary, start with 16. It fits, leaving 6. Next, 8 does not fit, so write 0. Then 4 fits, leaving 2; 2 fits, leaving 0; and 1 does not fit. The included places make 10110.

Code example

convert.jsjavascript
const decimal = 22;
console.log(decimal.toString(2)); // 10110
console.log(Number.parseInt('10110', 2)); // 22

Common mistakes

  • Reading 10110 as “ten thousand one hundred ten”; it is not decimal.
  • Starting binary place values at two instead of one.
  • Treating the base marker in 10110₂ as another digit.

Quiz

Knowledge check

A binary value has place values 8, 4, 2, and 1. If the bits are `1101₂`, which values are included?

Try it

Convert both ways

Convert decimal 19 to binary, then verify by adding its binary place values.

Key takeaways

  • Binary positions are powers of two.
  • A 1 includes a place value and a 0 excludes it.
  • Conversion works in both directions using place values.
View module overview