Binary

Overview

Binary, also known as base-2, is a way of representing numbers with only two digits (0 and 1). Numbers can be represented in any number base from 2 and up. Common number bases used in programming include base-2 (binary), base-10 (decimal) and base-16 (hex). Decimal or base-10 which includes 10 digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) is what humans generally use for our everyday exchange of numbers.

Since computers (and microcontrollers) are only capable of storing information in one of two states, all information from a simple number to a full-length video is stored in binary on computers. Though we mostly write numbers in decimal in our code, it is sometimes more convenient to use binary or hexadecimal. We will discuss hexadecimal in a later lesson. Below is table showing all three.

Base Table

Format Name

Base

Digits

Total Digits

Binary

Base 2

0, 1

2

Decimal

Base 10

0, 1, 2, 3, 4, 5, 6, 7, 8, 9

10

Hexadecimal (Hex)

Base 16

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

16

Counting in binary is similar to counting in decimal except with different place values. Below is a table showing the place values for both decimal and binary.

_images/decbin.png

Exercise

  1. Copy the binary portion of the above table in your notebook, leaving out the zeros and ones.

  2. On this table write the numbers 10, 30, 35, 112, and 87 in binary.

  3. In your note book copy the following numbers in binary and provide their decimal equivalent.

00101010
00111100
01000001