# Connexions

You are here: Home » Content » Number Systems - Example Problems

### Recently Viewed

This feature requires Javascript to be enabled.

# Number Systems - Example Problems

Module by: Subhash Doshi. E-mail the authorEdited By: Elec and Comp 326

Summary: 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×102+2×101+1×100 321 3 10 2 2 10 1 1 10 0
(1)
5023=5×103+0×102+2×101+3×100 5023 5 10 3 0 10 2 2 10 1 3 10 0
(2)

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

23=10111 (binary)=1×24+0×23+1×22+1×21+1×20 23 10111 (binary) 1 2 4 0 2 3 1 2 2 1 2 1 1 2 0
(3)

## Binary - Unsigned

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

### Exercise 1

What is the decimal value of 10101 ?

#### Solution

1. Step 1. Know which system you are dealing with.:

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

2. Step 2. Write out the sum of each digit multiplied by its correct power of two depending on its position:
10101=1×24+0×23+1×22+0×21+1×20=1×24+1×22+1=16+4+1=21 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
(4)

### Exercise 2

Convert 011010 to decimal.

#### Solution

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

011010=0×25+1×24+1×23+0×22+1×21+0×20=16+8+(2=26) 011010 0 2 5 1 2 4 1 2 3 0 2 2 1 2 1 0 2 0 16 8 2 26
(5)

### Exercise 3

Convert the decimal number 47 to binary unsigned.

#### Solution

1. Step 1. Find the largest multiple of two less than or equal to the decimal number:

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

2. Step 2. Subtract the largest multiple from the decimal number.:
4732=15 47 32 15
(6)
3. Step 3. Repeat Step 1 and 2 until there is no remainder:
158=7 15 8 7
(7)
74=3 7 4 3
(8)
32=1 3 2 1
(9)
11=0 1 1 0
(10)
4. Step 4. Construct the binary number out of the powers of two subtracted from the decimal number:
47=32+8+4+2+1=25+23+22+21+20=101111(binary) 47 32 8 4 2 1 2 5 2 3 2 2 2 1 2 0 101111(binary)
(11)

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

## Binary Signed

### Exercise 4

Convert 11001110 (signed) to decimal value.

#### Solution

1. Step 1. Check most significant bit to see if it is negative or positive:

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

2. Step 2. Sum the powers of two for the bits after the most significant one:
1001110=26+23+22+21=64+8+4+2=78 1001110 2 6 2 3 2 2 2 1 64 8 4 2 78
(12)
3. Step 3. Attach the sign to the decimal number:

Thus the answer is -78.

### Exercise 5

Convert -98 to signed binary(8bit).

#### Solution

1. Step 1. The most significant bit holds the sign value:

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

2. Step 2. Subtract the largest multiple of 2 less than or equal to the decimal number:
9826=9864=34 98 2 6 98 64 34
(13)
3. Step 3. Repeat this step until there is no remainder. Note down the powers of two:
3425=3432=2 34 2 5 34 32 2
(14)
221=0 2 2 1 0
(15)
4. Step 4. Construct the decimal number from the powers of two from the previous steps:
98=(26+25+21)=11100010 98 2 6 2 5 2 1 11100010
(16)

### Exercise 6

Convert 98 to signed binary(8bit).

#### Solution

1. Step 1. The most significant bit holds the sign value:

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. Step 2. Subtract the largest multiple of 2 less than or equal to the decimal number:
9826=9864=34 98 2 6 98 64 34
(17)
3. Step 3. Repeat this step until there is no remainder. Note down the powers of two:
3425=3432=2 34 2 5 34 32 2
(18)
221=0 2 2 1 0
(19)
4. Step 4. Construct the decimal number from the powers of two from the previous steps:
98=26+25+21=01100010 98 2 6 2 5 2 1 01100010
(20)

## Binary - Two's Complement

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

 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

### Exercise 7

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

#### Solution

1. Step 1. The most significant bit holds the sign value following the same convention as signed binary:

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

2. Step 2. Since this number is positive, we can treat the remaining binary digits as per normal:
001011=1011=23+21+20=8+2+1=11 001011 1011 2 3 2 1 2 0 8 2 1 11
(21)

### Exercise 8

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

#### Solution

1. Step 1. Check the most significant bit for sign value:

The first bit is 1 so the number is negative.

2. Step 2. Invert the remaining bits:

11011 --> 00100

3. Step 3. Add 1 and calculate the decimal value of the number:
00100+1=00101=22+20=5 00100 1 00101 2 2 2 0 5
(22)
4. Step 4. Add the negative sign to decimal value.:

Thus the answer is -5.

### Exercise 9

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

#### Solution

1. Step 1. Use the sign of the decimal value to choose the most significant bit:

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

2. Step 2. Convert the decimal value into binary:
13=8+4+1=23+22+20=1101 13 8 4 1 2 3 2 2 2 0 1101
(23)
3. Step 3. Subtract 1 and invert the binary numbers:
11011=1100 1101 1 1100
(24)

1100 --> 0011

4. Step 4. Sign extend the number to the appropriate number of digits:

0011 --> 11110011

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

 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

### Exercise 10

Convert ABC (hexadecimal) to binary and decimal.

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

#### Solution

1. Step 1. Convert the letters to their decimal values using the table:

ABC --> 10 , 11 , 12

2. Step 2. Multiply the decimal values by the correct power of 16 based on their significant position. Add the values:
10×162+11×161+12×160=2560+176+12=2748 10 16 2 11 16 1 12 16 0 2560 176 12 2748
(25)
3. Step 3. Convert the decimal values to 4-bit binary numbers:

ABC --> 10 + 11 + 12 --> 1010 1011 1100

4. Step 4. The binary number can be constructed with these values simply by merging them:

1010 1011 1100 --> 101010111100

### Exercise 11

Convert 1010011110000001 to its decimal and hexadecimal values.

#### Solution

1. Step 1. Separate the binary number into blocks of 4 starting from the least significant bit:

1010011110000001 --> 1010 0111 1000 0001

2. Step 2. Convert each 4-bit block into its hexadecimal value to get the answer:

1010 0111 1000 0001 --> A781

3. Step 3. It is usually easier to convert from hexadecimal to decimal than from binary to decimal:

A781 --> 10, 7, 8, 1

10×163+7×162+8×161+1×160=40960+1792+128+1=42881 10 16 3 7 16 2 8 16 1 1 16 0 40960 1792 128 1 42881
(26)

## Content actions

PDF | EPUB (?)

### What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

For detailed instructions on how to download this content's EPUB to your specific device, click the "(?)" link.

### Add module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

#### Definition of a lens

##### Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

##### What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

##### Who can create a lens?

Any individual member, a community, or a respected organization.

##### What are tags?

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks