Binary Number Basics

Valentin Placido
3 min readFeb 20, 2020

--

Nearly completing an entire month at Flatiron I have learn new languages, concepts and, have retouched on programming topics I learned at college. But one topic I am surprised we have not been exposed to are Binary Numbers given computers reliance on binary numbers.

What is a Binary Number

  • Binary is a system of counting using only two digit’s 0 & 1
  • Unlike our Base 10 counting system Binary is a Base 2 system (ex 2⁰, 2¹, 2³, …)

Reading Binary Number

10101

Above is a five digit binary number. To read binary we have to read from left to right and can be shown as:

  • 1 = 2⁴ x 1 = 16
  • 0 = 2³ x 0 = 0
  • 1 = 2² x 1 = 4
  • 0 = 2¹ x 0 = 0
  • 1 = 2⁰ x 1 = 1

Know we can sum the decimals to give us the value of 21 so

21 = 10101

Binary To Decimal

Decimal to Binary

How are Binary Numbers used in Ruby?

While it may seem confusing how we will use binary in our programs, we have been using binary since the first day at Flatiron. In fact we have been always been using binary number when we use a computer just that we are not able to see how the computer processes binary.

One simple example we can use is by referencing to the ASCII Chart below.

In ruby if we use “65.chr”, ruby will output “A” but it does this through binary by telling the computer to convert the integer 65 to binary: 1000001 which will return the “A” character.

So if we are given: 1001000 1100101 1101100 1101100 1101111. We can convert each binary to a decimal.

  • 1001000 = (2⁶ x 1) + (2⁵ x 0) + (2⁴ x 0) + (2³ x 1) + (2² x 0) +(2¹ x 0) +(2⁰ x 0) = 64 + 0 + 0 + 8 + 0 + 0 +0 = 72 = H
  • 1100101 =(2⁶ x 1) + (2⁵x 1) + (2⁴ x 0) + (2³ x 0) + (2² x 1) +(2¹ x 0) +(2⁰ x 1) = 64 + 32+ 0 + 0+ 4+ 0 +1 = 101= e
  • 1101100 = (2⁶ x 1) + (2⁵ x 1) + (2⁴ x 0) + (2³ x 1) + (2² x 1) +(2¹ x 0) +(2⁰ x 0) = 64 + 32+ 0 + 8 + 4+ 0 +0 = 108= l
  • 1101100 = (2⁶ x 1) + (2⁵ x 1) + (2⁴ x 0) + (2³ x 1) + (2² x 1) +(2¹ x 0) +(2⁰ x 0) = 64 + 32+ 0 + 8 + 4+ 0 +0 = 108= l
  • 1101111 = (2⁶ x 1) + (2⁵ x 1) + (2⁴ x 0) + (2³ x 1) + (2² x 1) +(2¹ x 1) +(2⁰ x 1) = 64 + 32+ 0 + 8 + 4+ 2+1 = 111= o

So 1001000 1100101 1101100 1101100 1101111 = Hello

More Resources

Math is Fun

Binary YouTube

--

--

No responses yet