The following notes refer to material from Chapter 1.

Binary Notation (contd.):

Since the binary system is positional we may incorporate the idea of fractional values as we do for the decimal system. We may also consider the rules of arithmetic in this system. However, we will consider addition only. We will defer subtraction etc. until we discuss machine architecture.
See page section 1.5 of the text, particularly figures 1.17 and 1.18.

Fractional Values:

Consider the decimal number 15.72. We may express it thus:

15.72 = 1*101 + 5*100 + 7*10-1 + 2*10-2

Notice that the decimal point is merely a placeholder to indicate where the fractional part begins.

Binary fractional values are represented similarly. Consider 1011.1101:

1011.1101 = 1*23 + 0*22 + 1*21 + 1*20 + 1*2-1 + 1*2-2 + 0*2-3 + 1*2-4

Notice that the binary point is again a placeholder to indicate where the fractional part begins. Given this representation we may easily convert to decimal. That is, this binary number is 11.8125 in decimal.

Binary Addition:

The principle of binary addition is similar to decimal addition. However, remember that in the binary system the following rules apply: 0 + 0 = 0; 0 + 1 = 1; 1 + 0 = 1; 1 + 1 = 0 (carry 1).

e.g. 1011 + 0110 = 10001

We can confirm by converting to decimal: 11 + 6 = 17.

Hexadecimal Notation:

Although binary is the language of computers we usually find it more convenient to use another number system. This system also uses positional notation to represent numbers but this uses 16 symbols (0,1,...,9, a,b,c,d,e,f). This system is known as the hexadecimal system.

Converting Hexadecimal to Decimal

Make use of positional notation to complete the conversion. That is, if you consider the rightmost hexadecimal digit to be position zero, then as you move from right to left, each digit, corresponds to 16n where n is the position of the digit. Also, a corresponds to 10, b to 11, c to 12, d to 13, e to 14, f to 15.

e.g. The hexadecimal number b5 may be expressed thus:

b5 = b*161 + 5*160 = 11*161 + 5*160 = 181

e.g. The hexadecimal number 12f may be expressed thus:

12f = 1*162 + 2*161 + f*160 = 1*256 + 2*16 + 15 = 303

Note: To distinguish between the respective number systems we use subscripts to represent the base (recall that binary is base 2, decimal is base 10, hexadecimal is base 16). Hence 102=210. Similarly, as we saw in the example above b516=18110.

Converting Decimal to Hexadecimal

We may use an algorithm similar to that presented for Decimal to Binary presented last week.
Note: The text does not discuss Decimal to Hexadecimal conversion.

  1. Divide number by 16
  2. Note result and keep track of remainder (expressed as a hexadecimal digit).
  3. Let result be new number
  4. Repeat steps 1 to 3 until result is zero

Write down the remainders obtained at step 2 in reverse order to get the hexadecimal equivalent of the decimal number.

Practice Problems

Convert each of the following decimal numbers to hexadecimal.

  1. 10010
  2. 25110
  3. 101210

Solution:

  1. 100 divided by 16 is 6 remainder 4; 6 divided by 16 is 0 remainder 6.
    Hence 10010 = 6416
  2. 251 divided by 16 is 15 remainder 11 (i.e. b16); 15 divided by 16 is 0 remainder 15 (i.e. f16)
    Hence 25110 = fb16
  3. 1012 divided by 16 is 63 remainder 4; 63 divided by 16 is 3 remainder 15 (i.e. f16); 3 divided by 16 is 0 remainder 3
    Hence 101210 = 3f416

Converting Hexadecimal to Binary & Binary to Hexadecimal

Since we know how to convert between decimal and hexadecimal we could simply accomplish this by first converting to decimal as an intermediate step. However, we need not take this approach. A much simpler technique is presented in the text (see pg 24). We will first outline the approach for binary to hexadecimal conversion.

Binary to hexadecimal:

  1. Partition the string of binary digits into groups of 4 bits starting at the right.
  2. Convert each group of 4 bits into its corresponding hexadecimal digit (see fig 1.6, pg 25).
e.g. 11111101002 may be partitioned thus 11 1111 0100 which is 3f416.

Hexadecimal to binary:

Convert each hexadecimal digit to its binary equivalent (see fig 1.6, pg 25) from left to right. The resulting string of binary digits is the corresponding binary number.

e.g. b516 would be 1011 0101 which is 101101012.

e.g. 6ae216 would be 110 1010 1110 0010 which is 1101010111000102.

Practice Problems

Work problems 5-6 on page 26 of the text.

 

Scientific Notation

As we often do for decimal numbers, particularly when they are very large or very small, we may use scientific notation to express binary numbers. First, a review of scientific notation for decimal numbers and some terminology.

Decimal numbers:

We may represent decimal numbers in scientific notation thus:

  1. 15.72 = 0.1572*102
  2. 640,000 = 0.64*106
  3. 0.0006734 = 0.6734*10-3
We may use the following shorthand notation since it is understood that we take the product of a fraction and 10 raised to some power.
  1. 15.72 = 0.1572 | 2
  2. 640,000 = 0.64 | 6
  3. 0.0006734 = 0.6734 |-3
We refer to the first part (i.e. the fractional value) as the mantissa and the second part as the exponent. Observe the following:
  1. The first significant digit (i.e the leftmost) is always adjacent to the decimal point. Notice that we do not write 0.06734 |-2 or 0.001572 | 4.
  2. The exponent tells us:
    1. The direction to move the decimal point to obtain the original number. That is, if the exponent is positive then we move the decimal point to the right and if it is negative we move it to the left.
    2. The number of places to move the decimal point.

Binary numbers:

Scientific notation for binary numbers works in the same way. The only difference is that we are using base 2, not base 10, and so we take the product of a fraction and 2 raised to some power. Hence, we may represent the following binary numbers in binary scientific notation thus:

  1. 1002 = 0.1*23 = 0.1 | 3
  2. 1001.12 = 0.10011*24 = 0.10011 | 4
  3. 0.00112 = 0.11*2-2 = 0.11 |-2
Again, the first significant digit is adjacent to the binary point and the exponent tells us the direction and number of positions to move the decimal point to obtain the original number.
Note: We usually express the exponent in binary but we will defer that representation until we revisit this topic (Week 3).