top of page
Writer's pictureErika Camilleri

Chapter 17 Binary Number Representation

Updated: Jul 10, 2022

Binary Decimal Conversions | Part 1 of 2

The Decimal Number System


This is the Arabic number system that we start learning from a very young age. We somehow learnt that a positive numerical value can be represented using some combination of any of the following ten digits:

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


We know by heart that the numerical value of fifty-two in decimal can be represented using digits '5' and '2'.


Let us imagine for a moment that we are trying to teach an alien our number system, and after instructing the alien to use the digits '5' and '2' to represent fifty-two it writes...


25


The alien did not disobey our instructions but we failed to mention perhaps that the order of the digits has an important meaning because we do it without thinking (oops!) This order in mathematics is formally referred to as positional notation. The diagram below illustrates how positional notation gives us a numerical value of fifty-two in a decimal number system.

The key take away here is that the digit '5' truly represents the numerical value of fifty due to its position. The digit '2' represents the numerical value of two due to its position also.


Why did we go through all this trouble of explaining this to an imaginary alien, you ask? This concept is applied to machine code also; turns out that it is an amazingly powerful way to represent information inside our computers.


The Binary System


In the human world, the decimal number system is so critical that naturally we needed to figure out a way to model an equivalent for our computers. We already learnt that internally we can only work with ones and zeroes. Therefore numbers must be represented by a pattern consisting of only two digits:

1, 0


This is possible using positional notation of course, but it does mean the pattern is going to be significantly longer. Let's give it a go with number fifty-two.

And there you have it, fifty-two in binary is written as "1 1 0 1 0 0".


Binary Decimal Conversion


Since both number systems are based on positional notation then it is perfectly possible to convert from one representation to another using simple algorithms.


Binary to Decimal

A binary representation can be converted to decimal by summing up the numerical values each digit represents.

Just a kind warning — we are entering a Math Buffs Only Zone. If you are not one of them don't worry just scroll down until you find the safety flag 🚩.

We can express the conversion mathematically, diagram below, using sum notation (sum notation is just a fancy way of writing a particular mathematical algorithm) where:

  • i refers to the index (start counting at 1) of the digit that is representing a value

  • n is the upper limit and is set to the length of the bit pattern being converted

  • d subscript i is the actual digit that is representing a value

Summation formula for binary to decimal conversion

🚩For example, let us consider the binary number that is 8 bits in length:

We have to loop through all the digits in the pattern and for each compute the numerical value determined by its position (or using the summation formula). Finally, sum up all the values together to get the final result. The diagram below shows how the value computes to 179. It is simpler than it sounds I promise!

⚠️Re-entering into the Math Buffs Only Zone (to find safety scroll down to 🚩), the diagram below explains how we are in fact putting the summation formula in action.

Making use of the summation formula to convert Binary to Decimal

If you ever programmed before and you are being reminded of a for loop then you are on the right track! For fun I put my CodePen that converts a binary number to a decimal.


🚩Decimal to Binary


Unfortunately the conversion in this direction is not as straight forward because we need to use mathematical concepts that you probably did not use yet! I will do my best to break it down here. It is important to remember that the digit position represents a numerical value. When converting a decimal number to a binary number one must ask what is the highest position going to be? In simpler terms how many ones and zeroes are we going to need? This is tricky because the position is an exponent or a power.


You probably already did power notation at school. What power do we need to give 2 so that we get 8? If you said 3 (which is correct) can you explain how you worked it out? Probably by trying it out until you got the desired result; but there is a mathematical way using a logarithmic function! If you take out your scientific calculator you should be able to find it.

Back to 179, let us use a calculator to find out how many bits are needed to represent this value.


We got quite a fuzzy result but there is a clear indication that the highest position is 7 so we definitely need eight bits to represent the value 179. Now that we have the highest position we can start building our conversion table as before.

Next, we shall apply a greedy algorithm to determine whether a numerical value at a particular position should be on or off for 179. We will start from the highest power and work our way down. At each position we will use a very simple condition on a remainder value r (in the beginning this is set to 179) to decide whether a position should be on or off. When we switch on a position the value of r changes, otherwise it just gets carried over to the next position. At the very end the combination of on and off switches give us the binary representation of the value.

Working With Multiple Number Systems


When we are doing some workings on paper and we are using multiple number systems in the same context, we specify the base of the number in subscript in order to avoid miscommunication.


We already mentioned that the machine's binary number system is base 2 and our decimal number system is base 10.

Hot Topic 🔥🔥


This is a topic that regularly comes out in exams. It is very important to practice as much as you can. Also, making mistakes is normal and it is very important to show your working clearly.

  1. Q. Any data needs to be converted to binary before it can be processed by the computer. Give the 8-bit binary value of the two denary values: 180 and 201. A. 180 = 10110100, 201 = 11001001 (workings below).

​180

​128

​64

32

16

8

4

2

1

​r = 180

​r = 52

​r = 52

​r = 20

​r = 4

​r = 4

r = 0​

​1

​0

​1

​1

​0

​1

0​

0​

201

​128

​64

​32

16

8

4

2

1

r = 201

​r = 73

r = 9

r = 9

r = 9

r = 1

r = 1

r = 1

1

1

0

0

1

0

0

1













493 views0 comments

Related Posts

See All

Comments


bottom of page