← Back to course
2/6
Week 09 Β· Bits and Binary

Tuesday

Binary to decimal and back
// Place values, one byte, overflow, and sampling a smooth curve
⏱ about 20 min

Tuesday: Binary to Decimal and Back

Beacon's log has a new column, and it is full of 0s and 1s.

"01001011," Comet reads aloud. "That looks like a phone keypad having a bad day."

Wren laughs, then writes the eight place values above the bits. "Let's investigate. Where are the 1s?"

"In the 64, the 8, the 2 and the 1," Comet says slowly.

Nova lights up those four places. "And together they make?" she asks.

Comet adds on her fingers. "75. It is the morning water reading!"

"Now do it backward," Wren says, and writes 100 at the top of a fresh page.

Binary to decimal

Write the place values over the bits. Then add the place values that sit over a 1.

We call our everyday numbers decimal, or base 10.

place value:  128  64  32  16   8   4   2   1
bits:           0   1   0   0   1   0   1   1

add the places with a 1:  64 + 8 + 2 + 1 = 75
CONVERT BINARY TO DECIMAL
  • Read the question.
  • Tap your answer.
What is 00001101 in decimal?
What is 11001000 in decimal?
What is 00101010 in decimal?

Decimal to binary

To go the other way, start at the biggest place value, 128, and work right.

If the place value fits into what is left, write 1 and subtract it. If not, write 0. Keep going until you reach the 1 place.

Convert 100 into one byte:
128 fits into 100?  no   -> 0   (100 left)
 64 fits into 100?  yes  -> 1   (36 left)
 32 fits into  36?  yes  -> 1   (4 left)
 16 fits into   4?  no   -> 0
  8 fits into   4?  no   -> 0
  4 fits into   4?  yes  -> 1   (0 left)
  2 fits into   0?  no   -> 0
  1 fits into   0?  no   -> 0

100 = 01100100
PUT THE DECIMAL-TO-BINARY STEPS IN ORDER
  • ?Stop after the 1 place. The eight bits are the answer.
  • ?Start at 128 and ask whether it fits into the number.
  • ?Move one place to the right and ask again with what is left.
  • ?If it fits, write 1 and subtract it. If not, write 0.
  • ?Write the eight place values, from 128 down to 1.
WHY THIS EXERCISEConverting is an algorithm: a finite set of exact steps that always works.
CONVERT DECIMAL TO BINARY
  • Read the question.
  • Tap your answer.
Which byte is 13?
Which byte is 150?
What is the largest number one byte can hold?
Counting 0 to 255, how many different values can one byte hold?
StatementTrue or false?
00000000 is 0 in decimal.?
11111111 is 256 in decimal.?
The number 100 needs a 1 in the 64 place.?
A byte can hold the number 300.?
WHY THIS EXERCISEKnowing a byte's range from 0 to 255 prepares you for tomorrow's overflow.
Try it
Look at a clock or a calendar and pick three numbers you see, all under 256.
Convert each one into a byte, then convert it back to check your work.
On paper, make a conversion chart: write five Beacon readings of your choice from 0 to 255, then their bytes. Check each one by adding back.

Nice converting. Tomorrow's Beacon Lab uses paper bit cards and a curve.

← Monday