CSC110 - Computer Mathematics

Module 2 Section 3- Conversion Techniques

The goal for this module is that you be able to understand the binary, octal, decimal and hexadecimal number systems, and that you be able to convert a number in any of these systems to any of the other systems. We still have one little problem to deal with. Consider the following number:

What is this number? What system is it written in? Obviously it cannot be binary, because it has digits which are not allowed in binary numbers. But it could be octal, decimal, or hexadecimal. How can you tell?

From this point forward we will adopt a convention of notation. A convention is simply a way people have agreed to do something so that everyone understands what everyone else has done. Our convention for identifying the base of a number will be as follows:

  1. The base can be given as a subscript. This will work for any base, even the ones we have not studied.  For example, the number 356 is in base 6.
  2. A number which starts with a leading '0' (zero) is an octal number. The C programming language does this, and it is easy to get used to. If we write a leading zero then that means the rest of the number is octal. So 035 is octal 35.
  3. A number which starts with a $, a &, or '0x' is a hexadecimal number. The C programming lanuage uses '0x'. Turbo pascal uses '$'. Some assemblers use '&'. So $35, &35, and 0x35 are all hexadecimal 35.
  4. A number which ends with 'H' is a hexadecimal number. Some assemblers use this notation. 35H is hexadecimal 35.
  5. A number which ends in 'B' is a binary number. An example is 0101011011B. Some computer languages accept this notation.
  6. A number which is written plainly, having no subscript, prefix, or suffix, is assumed to be decimal.
We have already learned how to convert between binary and the other three systems (octal, decimal, and hexadecimal).  But what if you want to convert between, say, octal and decimal? or decimal and hexadecimal?. There are techniques for converting directly from one base to another. One way is to use binary form as an intermediate form when converting between the other bases.

For example, suppose you want to convert 24 to octal. First convert 24 to binary, then convert that to octal.

24 -> 11000B -> 030

What about converting hexadecimal number 0x3B to decimal? Again, first convert to binary, then to decimal.

0x3B -> 00111011B -> 25+24+23+21+20 = 32+16+8+2+1 = 59

However, some conversion can be done even more easily than this. Here are suggested ways to perform conversion between the bases:

Homework Questions

1-20. Complete the following table by filling in the empty cells. Each row is the same number written in different bases. Each column is the same base.
    Binary Octal Decimal Hexadecimal
      37   1F
Next Module: Computer Integer Arithmetic
Previous Section: Octal and Hexadecimal Number Systems
Return to Module Index