<< Chapter < Page Chapter >> Page >
Worked examples for converting between binary, decimal and hexadecimal.

The number systems

What are the different number systems?

We are all familiar with the decimal system. However, when working with computers, we need to start with the binary system. The reason for this is that computers use gates (or switches) which only have two states, on and off. This is what translates to the 1's and 0's of binary. From there, it is possible to build up to other more useful systems such as the decimal system or the hexadecimal system.

This module contains worked examples of how to convert between the decimal, hexadecimal and binary.

Powers of 10 and 2

Before working through some examples, it will be useful to review how we use the decimal system. The decimal system can express any real rational number using the digits 0-9 and a minus sign. The places of the digits represent the power of ten that is being used. For example:

321 3 10 2 2 10 1 1 10 0
5023 5 10 3 0 10 2 2 10 1 3 10 0

In the same way, binary systems use 1's and 0's to express a number:

23 10111 (binary) 1 2 4 0 2 3 1 2 2 1 2 1 1 2 0

Binary - unsigned

The following examples show how to convert between unsigned binary and decimal values.

What is the decimal value of 10101 ?

  1. In this case, we are dealing with unsigned binary numbers. Our range of possible numbers are between 0 and 2 N 1 .

  2. 10101 1 2 4 0 2 3 1 2 2 0 2 1 1 2 0 1 2 4 1 2 2 1 16 4 1 21

Convert 011010 to decimal.

Write out the sum of each digit multiplied by its correct power of two:

011010 0 2 5 1 2 4 1 2 3 0 2 2 1 2 1 0 2 0 16 8 2 26

Convert the decimal number 47 to binary unsigned.

  1. For the decimal number 47, the largest multiple of two is 32 ( 2 5 ).

  2. 47 32 15
  3. 15 8 7
    7 4 3
    3 2 1
    1 1 0
  4. 47 32 8 4 2 1 2 5 2 3 2 2 2 1 2 0 101111(binary)

    Note: If necessary, you can check your answer by reversing the steps and converting it back to decimal.

Binary signed

Convert 11001110 (signed) to decimal value.

  1. The most significant bit is 1. This means it is negative.

  2. 1001110 2 6 2 3 2 2 2 1 64 8 4 2 78
  3. Thus the answer is -78.

Convert -98 to signed binary(8bit).

  1. In this case, the decimal number is negative so the most significant bit is 1.

  2. 98 2 6 98 64 34
  3. 34 2 5 34 32 2
    2 2 1 0
  4. 98 2 6 2 5 2 1 11100010

Convert 98 to signed binary(8bit).

  1. In this case, the decimal number is negative so the most significant bit is 0.

    Since we have already calculated the binary representation for 98, we can use the answer from the previous example. The steps are shown again to illustrate this.

  2. 98 2 6 98 64 34
  3. 34 2 5 34 32 2
    2 2 1 0
  4. 98 2 6 2 5 2 1 01100010

Binary - two's complement

The table below is a refresher for two's complement.

Two's complment
Two's Complement Decimal
0111 7
0110 6
0101 5
0100 4
0011 3
0010 2
0001 1
0000 0
1111 -1
1110 -2
1101 -3
1100 -4
1011 -5
1010 -6
1001 -7
1000 -8

Convert 001011 (two's complement 6-bit) to decimal value.

  1. In this case, the most significant bit is 0. The number is positive.

  2. 001011 1011 2 3 2 1 2 0 8 2 1 11

Convert 111011 (two's complement 6-bit) to decimal value

  1. The first bit is 1 so the number is negative.

  2. 11011 -->00100

  3. 00100 1 00101 2 2 2 0 5
  4. Thus the answer is -5.

Convert -13 to two's complement 8-bit binary.

  1. The number is negative so the most significant bit will be 1.

  2. 13 8 4 1 2 3 2 2 2 0 1101
  3. 1101 1 1100

    1100 -->0011

  4. 0011 -->11110011

Hexadecimal

A reference table is attached for conversion between decimal, hexadecimal and binary.

Hexadecimal reference
Decimal Hexadecimal Binary
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
10 A 1010
11 B 1011
12 C 1100
13 D 1101
14 E 1110
15 F 1111

Convert ABC (hexadecimal) to binary and decimal.

It may sometimes be easier to convert to decimal first and then binary.

  1. ABC -->10 , 11 , 12

  2. 10 16 2 11 16 1 12 16 0 2560 176 12 2748
  3. ABC -->10 + 11 + 12 -->1010 1011 1100

  4. 1010 1011 1100 -->101010111100

Convert 1010011110000001 to its decimal and hexadecimal values.

  1. 1010011110000001 -->1010 0111 1000 0001

  2. 1010 0111 1000 0001 -->A781

  3. A781 -->10, 7, 8, 1

    10 16 3 7 16 2 8 16 1 1 16 0 40960 1792 128 1 42881

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Precalculus with engineering applications. OpenStax CNX. Jan 24, 2011 Download for free at http://cnx.org/content/col11267/1.3
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Precalculus with engineering applications' conversation and receive update notifications?

Ask