# Module 1.2

# Converting Between Number Systems

- After studying this section, you should be able to:
- Convert numerical data between number systems.
- • Decimal.
- • Binary.
- • Octal.
- • Hexadecimal.
- Understand the relationships between number systems used in digital electronics.
- • Decimal fractions
- • Decimal & hexadecimal.

It is often necessary to convert values written in one number system to another. The simplest way is to reach for your calculator or use a conversion app. from the web. That is fine, but converting a number in this way does not help you to understand the way each number system works and how different systems are related. The purpose of this module is to explain just that, and to get you to carry out some simple conversions so that you can not only convert between number systems, but also understand how the conversion process works. There are various ways to tackle conversions without a calculator; once the conversion methods are learned, the only skills needed are the ability to multiply and divide, and to add together a few numbers.

## Conversion from any system to decimal

The number of values that can be expressed by a single digit in any number system is called the system radix, and any value can be expressed in terms of its system radix.

### Octal to Decimal

For example the system radix of octal is 8, since any of the 8 values from 0 to 7 can be written as a single digit.

Convert 126_{8} to decimal.

Using the values of each column, (which in an octal integer are powers of 8) the octal value 126_{8} can also be written as:

(1x8^{2}) + (2x8^{1}) + (6 x 8^{0})

As (8^{2} = 64), (8^{1} = 8) and (8^{0} =1), this gives a multiplier value for each column.

Multiply the digit in each column by the column multiplier value for that column to give:

1x64 = 64 2x8 =16 6x1 = 6

Then simply add these results to give the decimal value.

64 + 16 + 6 = 86_{10}

Therefore 126_{8} = 86_{10}.

### Binary to Decimal

Convert 1101_{2} to decimal.

The same method can be used to convert binary number to decimal:

= (1x2^{3})+(1x2^{2})+(0x2^{1})+(1x2^{0})

= 8 + 4 +0 +1

= 13_{10}

Therefore 1101_{2} = 13_{10}.

### Hexadecimal to Decimal

Convert B2D_{16} to decimal.

Using the same method to convert hexadecimal to decimal.

= (Bx16^{2})+(2x16^{1})+(Dx16^{0})

= (11x16^{2})+(2x16^{1})+(13x16^{0})

= 2816 + 32 +13

= 2861_{10}

Therefore B2D_{16} = 2861_{10}.

The same method (multiplying each digit by it's column value) can be to convert any system to decimal.

### Try these conversions to decimal WITHOUT USING YOUR CALCULATOR FOR THE ACTUAL CONVERSION.

110_{2} 67_{8} AFC_{16} FC_{16}

### How do you know if your answer is correct?

### Convert your decimal answer back into its original format.

## Converting from Decimal to any Radix

To convert a decimal integer number (a decimal number in which any fractional part is ignored) to any other radix, all that is needed is to continually divide the number by its radix, and with each division, write down the remainder. When read from bottom to top, the remainder will be the converted result.

### Decimal to Octal

##### Example 1.2.2 Decimal to Octal Conversion

For example, to convert the decimal number 86_{10} to octal:

Divide 86_{10} by the system radix, which when converting to octal is 8. This gives the answer 10, with a remainder of 6.

Continue dividing the answer by 8 and writing down the remainder until the answer = 0

Now simply write out the remainders, starting from the bottom, to give 126_{8}

Therefore 86_{10} = 126_{8}

### Decimal to Binary

##### Example 1.2.1 Decimal to Binary Conversion

This process also works to convert decimal to binary, but this time the system radix is 2:

For example, to convert the decimal number 13_{10} to binary:

Therefore 13_{10} = 1101_{2}

### Decimal to Hexadecimal

##### Example 1.2.3 Decimal to Hexadecimal Conversion

It also works to convert decimal to hexadecimal, but now the radix is 16:

As some of the remainders may be greater than 9 (and so require their alphabetic replacement), you may find it easier to use Decimal for the remainders, and then convert them to Hex.

Therefore 2861_{10} = B2D_{16}

## Numbers with Fractions

It is very common in the decimal system to use fractions; that is any decimal number that contains a decimal point, but how can decimal numbers, such as 34.625_{10} be converted to binary fractions?

In electronics this is not normally done, as binary does not work well with fractions. However as fractions do exist, there has to be a way for binary to deal with them. The method used is to get rid of the radix (decimal) point by NORMALISING the decimal fraction using FLOATING POINT arithmetic. As long as the binary system keeps track of the number of places the radix point was moved during the normalisation process, it can be restored to its correct position when the result of the binary calculation is converted back to decimal for display to the user.

However, for the sake of completeness, here is a method for converting decimal fractions to binary fractions. By carefully selecting the fraction to be converted, the system works, but with many numbers the conversion introduces inaccuracies; a good reason for not using binary fractions in electronic calculations.

### Converting the Decimal Integer to Binary

##### Example 1.2.4 Converting the Integer to Binary

The radix point splits the number into two parts; the part to the left of the radix point is called the INTEGER. The part to the right of the radix point is the FRACTION. A number such as 34.625_{10} is therefore split into 34_{10} (the integer), and .625_{10} (the fraction).

To convert such a fractional decimal number to any other radix, the method described above is used to covert the integer.

So 34_{10} = 100010_{2}

### Converting the Decimal Fraction to Binary

##### Example 1.2.5 Converting the Fraction to Binary

To convert the fraction, this must be MULTIPLIED by the radix (in this case 2 to convert to binary). Notice that with each multiplication a CARRY is generated from the third column. The Carry will be either 1 or 0 and these are written down at the left hand side of the result. However when each result is multiplied the carry is ignored (don’t multiply the carry). Each result is multiplied in this way until the result (ignoring the carry) is 000. Conversion is now complete.

For the converted value just read the carry column from top to bottom.

So 0.625_{10} = .101_{2}

Therefore the complete conversion shows that 34.62510 = 100010.101_{2}

However, with binary, there is a problem in using this method, .625 converted easily but many fractions will not. For example if you try to convert .626 using this method you would find that the binary fraction produced goes on to many, many places without a result of exactly 000 being reached.

With some decimal fractions, using the above method will produce carries with a repeating pattern of ones and zeros, indicating that the binary fraction will carry on infinitely. Many decimal fractions can therefore only be converted to binary with limited accuracy. The number of places after the radix point must be limited, to produce as accurate an approximation as required.

## Quick Conversions

The most commonly encountered number systems are binary and hexadecimal, and a quick method for converting to decimal is to use a simple table showing the column weights, as shown in Tables 1.2.1a and 1.2.1b.

### Converting Binary to Decimal

To convert from binary to decimal, write down the binary number giving each bit its correct ‘weighting’ i.e. the value of the columns, starting with a value of one for the right hand (least significant) bit. Giving each bit twice the value of the previous bit as you move left.

### Example:

To convert the binary number 01000011_{2} to decimal. Write down the binary number and assign a ‘weighting’ to each bit as in Table 1.2.1a

Now simply add up the values of each column containing a 1 bit, ignoring any columns containing 0.

Applying the appropriate weighting to 01000011 gives 64 + 2 + 1 = 67Therefore: 01000011_{2} = 67_{10}

### Converting Hexadecimal to Decimal

A similar method can be used to quickly convert hexadecimal to decimal, using Table 1.2.1b

The hexadecimal digits are entered in the bottom row and then multiplied by the weighting value for that column.

Adding the values for each column gives the decimal value.

Therefore: 25CB_{16} = 9675_{10}

### Now try some conversions yourself. Use pencil and paper to practice the method, rather than just finding the answer.

### Convert:

11010011_{2} to decimal.

10111011_{2} to decimal.

34F2_{16} to decimal.

FFFF_{16} to decimal.

Check your answer by converting the decimal back to binary or hexadecimal.

Don’t use your calculator - you need to learn the method, not just the answer!

## Binary and Hexadecimal

Converting between binary and hexadecimal is a much simpler process; hexadecimal is really just a system for displaying binary in a more readable form.

Binary is normally divided into Bytes (of 8 bits) it is convenient for machines but quite difficult for humans to read accurately. Hexadecimal groups each 8-bit byte into two 4-bit nibbles, and assigns a value of between 0 and 15 to each nibble. Therefore each hexadecimal digit (also worth 0 to 15) can directly represent one binary nibble. This reduces the eight bits of binary to just two hexadecimal characters.

### For example:

11101001_{2} is split into 2 nibbles 1110_{2} and 1001_{2} then each nibble is assigned a hexadecimal value between 0 and F.

The bits in the most significant nibble (1110_{2}) add up to 8+4+2+0 = 14_{10} = E_{16}

The bits in the least significant nibble (1001_{2}) add up to 8+0+0+1 = 9_{10} = 9_{16}

Therefore 11101001_{2} = E9_{16}

Converting hexadecimal to binary of course simply reverses this process.