Binary Numbers

Sameer Mahajan
4 min readDec 4, 2021

Introduction

What are binary numbers? Numbers like

0

1

10

10110111

Are all binary numbers. So how does one define a binary number?

Definition: Any sequence of 0s and 1s is a binary number.

Note: Such a sequence typically does not have any leading zeroes. E.g. one does not write 0101 or 00101 but only 101 as they are all the same number.

Exercise: Write 5 binary numbers

Decimal Numbers

The numbers that we usually use are like

1

2

10

93456

78154768

Which are called decimal numbers. A decimal number consists of digits that range from 0 to 9. These are also called base 10 numbers since all the digits are lower than the smallest number of 10. Binary numbers are called as base 2 numbers.

Base

The base of a number is denoted by subscript. A number N in base b is represented as

The base subscript is often omitted for decimal numbers since it is commonplace and the default. The subscript is omitted for numbers in other bases as well since it can be typically deduced looking at the digits. The base of a number is also used in computing the value of a number along with its digits. The digits are multiplied by raising the base to its power. Consider an m digit number in base b as

The place value of its i’th digit is computed by raising base b to the power i.

Converting a number from base b

The value of above m digit number in base b is computed as

Converting a number to base b

Base b is also used in converting a number to base b by continuously subtracting the powers of b from the number as illustrated below. A number N is getting converted to base b number in the process.

The divisors are written below the number and remainders are written to the right. We continuously keep dividing the number N and its divisors by b until the divisor is smaller than number b. In other words it cannot be divided by b any further. The above illustration shows that number N is same as 4 digit number in base b as below:

Convert binary number to decimal

To simplify these formulae let’s convert a binary number to decimal as an illustration. Let’s say the binary we want to convert is

Then it will be converted to

Convert decimal number to binary

Similarly as an illustration we will convert a decimal number to binary

Thus

Base 16 and Base 8

Base 16 numbers are special in the context of computing and are called as hexadecimal numbers. They consist of digits 0 through 15. To avoid any confusion with corresponding decimal numbers, the digits 10 through 15 are represented by letters A through F. Thus

A decimal number can be converted into a hexadecimal number by similar method as given above. Here is an illustration

Thus

Base 8 numbers are called as octal numbers. Using methods illustrated here one can convert number from any base b1 to any other base b2.

Exercises

1. Convert following binary numbers into decimal

a. 10111011

b. 11100111

2. Convert following decimal numbers into binary

a. 986

b. 356

3. Convert following decimal numbers into hexadecimal

a. 1738

b. 478

4. Convert following hexadecimal numbers into decimal

a. FA32

b. 7A4C

5. Convert following binary numbers into hexadecimal

a. 11110011010

b. 1011100011

6. Convert following hexadecimal numbers into binary

a. 3A2

b. 4F

PJ

Why did computer scientist confuse between Christmas and Halloween?

.

.

.

Because 25 DEC = 31 OCT

Number 25 in decimal is same as number 31 in octal (3 * 8 + 1 = 25)!

--

--

Sameer Mahajan

Generative AI, Machine Learning, Deep Learning, AI, Traveler