You are on page 1of 13

Chapter 2 – Number Systems

·         This chapter covers the following main topics:


o        Background
o        Counting in different bases
o        Range Calculations
o        Integer conversion
o        Fraction conversion
o        Arithmetic in different bases

Background

·         A number system is a representation method for numbers


·         A number system is identified by its base
·         The base is a decimal unsigned integer with a minimum value of 2
·         The is no limit on the maximum value for the base, however, the largest known base is 16
·         Commonly used number systems are also identified by their name
·         There are 4 commonly used number systems:
o        Decimal                         base 10
o        Hexadecimal                 base 16
o        Octal                              base 8
o        Binary                           base 2
·         The base determines the range of a digit in the number system which starts with 0 and ends with
base-1
·         For bases with range exceeding 10, the A-Z alpha symbols are used to represent values greater
than 9
Examples
o        Base 10 digit range is 0 – 9
o        Base 5 digit range is 0 - 4
o        Base 16 digit range is 0 – 9 and A – F
 
·         Computers internally stores and process data using the binary system
o        Binary is compatible with the computer hardware architecture which is based on Boolean
digital logic
o        Binary is base 2 with a digit range of 0 - 1
o        A binary digit is also known as bit
 
·         Most computers use the hexadecimal or the octal number systems in programming and
debugging
o        Hexadecimal is also known as hex
o        Hex is base 16 with a digit range of 0 – 9, A – F
o        Octal is base 8 with a digit range of 0 – 7
 
Advantages
o        Both number systems can be used as a short hand notation for binary
o        More readable than binary and hence easier for humans to work with
o        Easy to convert into and from binary
 
·         Humans on the other hand, work with the decimal system
·         Conversion between binary and decimal is necessary to make human to machine interaction
possible
·         Conversion between the different number systems is also possible
·         Conversion does not change the magnitude of the number

Counting in Different Bases

·         Counting is the process of repeatedly adding 1 to the number


o        Going through a complete digit range, exhausting all possible combinations
o        Shift to the left one place
o        Repeat as necessary until the number is completely represented
 
·         Theoretically, the counting process can continue indefinitely
·         However, there is always a limit on the available digits to store a number (storage size)
·         Therefore, counting process will stop when all the available digits are exhausted
·         Overflow will occur when storage size limit is exceeded
·         The following table shows a count in hexadecimal, decimal, octal, and binary
Hexadecimal                         Decimal                 Octal                      Binary
                0                                              0                             0                                   0
                1                                              1                             1                                   1
                2                                              2                             2                                 10
                3                                              3                             3                                 11
                4                                              4                             4                               100
                5                                              5                             5                               101
                6                                              6                             6                               110
                7                                              7                             7                               111
                8                                              8                             10                            1000
                9                                              9                             11                            1001
                A                                             10                            12                            1010
                B                                             11                            13                            1011
                C                                             12                            14                            1100
                D                                             13                            15                            1101
                E                                              14                            16                            1110
                F                                              15                            17                            1111
     10                                               16                            20                         10000
               
Range Calculations

·         The range of a number that can be represented is determined by:


o        Storage size                 number of digits
o        Base                               of the number system used to represent the number
·         Range can be computed as: (result in decimal)
R = Bn            (R = Range, B = Base, n = number of digits)
 
Examples
8 binary bits range                      28 = 25610
3 decimal digits range                103 = 100010
3 digits in hex range                   163 = 409610
 
·         Binary range calculations is often required in computers
Examples
o        Integer number data unit range with storage size of 16 bits = 216 = 65536
o        Memory addressing capability MAR size of 32 bits = 232 = 4GB
 
·         Range can also be computed as the product of its sub-ranges
32 binary bits range                   210 X 210 X 210 X 22 = 1K X 1K X 1K X 4 = 4G
12 binary bits range                   210 X 22 = 1K X 4 = 4K

Integer Conversion

Decimal to any base conversion


·         Method 1: Division by the base
o        Calculations is done using a tabular form of the following headings (New Base, From
base number, Remainder)
o        Divide until the from base number reaches zero
o        The remainder column is the conversion result
o        A remainder digit should never be greater than new base - 1
o        Copy the remainder digits from bottom to top
 
Examples
·         Convert 612410 to base 5
New Base      From Base Number             Remainder           
5                      6124                                        4                              least significant digit
5                      1224                                        4
5                      244                                          4                             
5                      48                                            3
5                      9                                              4                                              ↑
5                      1                                              1                              most significant digit
                        0
= 1434445
 
·         Convert 815110 to hexadecimal
New Base      From Base Number             Remainder           
16                    8151                                        7                              least significant digit
16                    509                                          13           
16                    31                                            15                                            ↑
16                    1                                              1                              most significant digit
                        0
= 1FD716
 
·         Convert 6410 to binary
New Base      From Base Number             Remainder           
2                      64                                            0                              least significant digit
2                      32                                            0             
2                      16                                            0
2                      8                                              0             
2                      4                                              0             
2                      2                                              0                                              ↑
2                      1                                              1                              most significant digit
0
= 10000002
 
·         Method 2 (you are not required to learn this method)
o        See example to convert 612410 to base 5 in page 42
o        See another example to convert 319310 to binary in page 42
 
Any base to decimal conversion
·         Method 1: sum of weight times digit
o        Compute the weight of each digit
o        SUM of: weight times digit
 
Integer Digit Weight Calculations
·         A digit weight is computed as:  (result is always in decimal)
W = Bn           (W = Weight, B = base, n = digit position)
o        Digit position numbering starts from the least significant digit and ends with the most
significant digit
o        Digit position starts at 0 and ends with the number of digits – 1
 
Examples
·         4-digit decimal weight calculation           103, 102, 101, 100     = 100010, 10010, 1010, 110
·         4-bit binary weight calculation 23, 22, 21, 20                    = 810, 410, 210, 110
·         4-digit octal weight calculation                83, 82, 81, 80             = 51210, 6410, 810, 110
 
Note: that any base power 0 = 1
 
·         Each digit has n times the weight of its next rightmost neighbor (where n is the base)
o        In binary each digit has twice the weight of its next right neighbor
o        In decimal each digit has 10 times the weight of its next rightmost neighbor
 
Conversion Examples
·         Convert 137548 to decimal
= 4 x 80  + 5 x 81 + 7 x 82 + 3 x 83 + 1 x 84
= 4 x 1 + 5 x 8 + 7 x 64 + 3 x 512 + 1 x 4096
= 612410
 
·         Convert 100012 to decimal
=  1 x 20  + 0 x 21 + 0 x 22  + 0 x 23 + 1 x 24
= 1 + 0 + 0 + 16
= 1710
 
·         Convert 10100012 to decimal
= 1 + 16 + 64
= 8110
Note: Conversion from binary is easy and can be computed as sum of weights of 1’s digits
 
·         Convert 53D16 to decimal
=  13 x 160 + 3 x 161 + 5 x 162
= 13 + 48 + 1280
= 134110
 
·         Method 2 (you are not required to learn this method)
o        See example to convert 137548 to decimal in page 44
 
Convert between related bases
·         Two number systems are related when one number system base is an integral power of the other
·         A single digit in the larger base requires n digits in the smaller base (where n is the power value)
·         Octal is related to binary since it takes 3 binary digits to represent 1 octal digit (23 = 8)
·         Hex is related to binary since it takes 4 binary digits to represent 1 hex digit (24 = 16)
·         Hex and octal, however, are not related
·         Conversion between related number systems is direct
·         Use a trial and error method to determine if two bases are related
o        Smaller base power 2, 3, 4, and so on…
o        If result = larger base, then the two bases are related
o        If result exceed larger base, then the two bases are not related
 
Examples
1.        Are 2 and 16 related
22 = 4
23 = 8
24 = 16             base 2 and 16 are related
 
2.        Are 3 and 8 related
32 = 9               base 3 and 8 are not related
 
Smaller base to Larger base conversion method
·         Determine the n value
·         Construct a conversion table (i.e. counting table as seen above is an example of conversion table)
·         Group the number into groups of n digits
·         Must start grouping from the right (i.e. least significant digit)
·         Pad with zeros if last group is less than n digits
·         Group by group, perform direct conversion using the conversion table
 
Examples
·         Convert 110101110110002 to hex
o        4 binary digits are required to represent a single hex digit (i.e. n  = 4)
o        Refer to the conversion table above
o        Group the number into groups of 4 digits:           11 0101 1101 1000
o        Pad last group with zeros:                                  0011 0101 1101 1000
o        Convert each group to their equivalent hex digit
= 35D816
 
·         Convert 110101110110002 to octal
o        3 binary digits are required to represent a single octal digit (i.e. n  = 3)
o        Refer to the conversion table above
o        Group the number into groups of 3 digits:           11 010 111 011 000
o        Pad last group with zeros:                                    011 010 111 011 000
o        Convert each group to their equivalent octal digit
= 327308
 
·         Convert 110101110110002 to base 4
o        2 binary digits are required to represent a single base 4 digit (i.e. n  = 2)
o        Construct a conversion table
Base 4            Binary
0                                 00
1                                 01
2                                 10
3                                 11
o        Group the number into groups of 2 digits:       11 01 01 11 01 10 00
o        Convert each group to their equivalent hex digit
= 311312016
 
Larger base to Smaller base conversion
·         Determine the n value
·         Construct a conversion table (i.e. counting table as seen above)
·         Digit by digit, perform direct conversion using the conversion table
 
Notes: don’t miss padding leading zeros to fill the n digits in the smaller base
 
Examples
·         Convert 35D816 to binary           
o        Each hex digit requires 4 binary digits (i.e. n = 4)
o        Refer to the conversion table above
o        Map each digit to its equivalent binary digits
= 0011 0101 1101 10002
 
·         Convert 2753318 to binary          
o        Each octal digit requires 3 binary digits (i.e. n = 3)
o        Refer to the conversion table above
o        Map each digit to its equivalent binary digits
= 010 111 101 011 011 0012
 
·         Convert 212234 to binary            
o        Each base 4 digit requires 2 binary digits (i.e. n = 2)
o        Refer to the base 4 to binary conversion table above
o        Map each digit to its equivalent binary digits
= 10  01 10 10 112
 
Convert between none decimal and none related number systems
·         It is impractical to directly convert between none decimal number systems that are not related
·         Decimal can be used as an intermediary conversion base
·         As well, a base that is related to both bases can be used as an intermediary conversion base
·         Binary can be used as an intermediate conversion base to convert between hex and octal
 
Examples
·         Convert 35D816 to octal               (note that the two bases are none decimal and are not
related)
o        Convert the number to binary                            = 00110101110110002
o        Convert the binary result to octal                     = 011 010 111 011 000
= 327302
 

·         Convert 21203 to base 5               (note that the two bases are none decimal and are not
related)
o        There is no intermediate base that is related to both bases so we use decimal as an
intermediate base
o        Convert the number to decimal                          = 0 x 30 + 2 x 31 + 1 x 32 + 2 x 33 = 6910
o        Convert the decimal result to base 5                 = 2345
= 2345

Fraction conversion

·         Fraction number conversion does not always result in an accurate result due to:
o        Representation of a fraction number that is possible in one base may be impossible to
represent in another base
o        If precise conversion cannot be done, conversion will result in lose of accuracy (i.e. lose of
significant digits)
 
Examples
§         0.110 is impossible to represent in binary (0.0001100110011…)
§         0.13 is impossible to represent in decimal (0.333333…)
 
·         When converting a number that contains both integer and fraction parts
o        The two parts must be converted separately
o        The fraction point must remain at its original location
 
1. Decimal to any number base conversion
·         Method 1: Multiply the fraction by the base
o        Calculations is done using a tabular form of the following headings (New Base, From
base number, Integer part)
o        Multiply from base number by new base repeatedly until the from base number reaches
zero
o        The Integer part column is the conversion result
o        An Integer part digit should never be greater than new base - 1
o        Copy the Integer part digits from top to bottom
 
Note: It is possible that conversion may not reach closure
 
Examples
·         Convert .82812510 to binary
New Base      From Base Number             Integer Part
2                      .828125                                   1                              most significant digit
2                      .65625                                     1                                              ↓
2                      .3125                                       0
2                      .625                                         1
2                      .25                                           0
2                      .5                                             1                              least significant digit
                        0             
= .1101012
 
·         Convert .110 to binary                  (this example will not reach closure)
New Base      From Base Number             Integer Part
2                      .1                                             0                              most significant digit
2                      .2                                             0                                              ↓
2                      .4                                             0
2                      .8                                             1
2                      .6                                             1
2                      .2                                             0                              repeat detected
= .000110011…2
 
·         Convert .72510 to octal                 (this example will not reach closure)
New Base      From Base Number             Integer Part
8                      .725                                         5                              most significant digit
8                      .8                                             6                                              ↓
       8                       .4                                             3
       8                       .2                                             1
       8                       .6                                             4
       8                       .8                                             6                              repeat detected
= .5631463146…8
 
2. Any number base to decimal conversion
·         Method 1: sum of weight times the digit
o        This method requires the calculation of the digits’ weight
 
Fraction Digit Weight Calculations
·         Fraction digit weight is computed as:  (result in decimal)
W = B-n = 1/Bn              (W = Weight, B = base, n = digit position)
o        Digit position numbering starts from the most significant digit and ends with the least
significant digit
o        Digit position starts from 1 and ends with the number of digits
 
Examples
·         3-digit decimal weight calculation           10-3, 10-2, 10-1              = 1/100010, 1/10010, 1/1010
·         3-bit binary weight calculation 2-3, 2-2, 2-1                = 1/810, 1/410, 1/210
·         3-digit octal weight calculation                8-3, 8-2, 8-1               = 1/51210, 1/6410, 1/810
 
Examples
·         Convert .122013 to decimal
= 1 x 1/31 + 2 x 1/32 + 2 x 1/33 + 0 1/34 x 1/35 + 1 x 1/ 36            
= 1 x 1/3 + 2 x 1/9 + 2 x 1/27 + 0 x 1/81 + 1 x 1/ 243  
= (81 + 2 x 27 + 2 x 9 + 1) / 243 = 154 / 243
= .6337410
 
·         Convert .110012 to decimal
= 1/21 + 1/22 + 1/25       
= 1/2 + 1/4 + 1/32         
= (16 + 8 + 1) / 32 = 25 / 32
= .7812510
 
·         Convert .2378 to decimal
= 2 x 1/81 + 3 x 1/82 + 7 x 1/83      
= 2 x 1/8 + 3 x 1/64 + 7 x 1/512    
= (128 + 24 + 7) / 512 = 159/512
= .31054687510
 
·         Convert .13 to decimal                 (does not convert accurately and round up or truncation is
needed)
= 1 x 1/3         
= 1/3
= .33333…10                         
 
3. Convert between Related number bases
·         Very similar to integer conversion with the following differences
o        Conversion start at the most significant digit (i.e. the digit to the right of the fraction point)
o        Padding with zeros of the last group is done to the right
o        The padding is more significant
 
Larger base to Smaller base conversion
·         Determine the n value
·         Construct a conversion table (i.e. counting table as seen above)
·         Digit by digit, perform direct conversion using the mapping table
 
Examples
·         Convert .4A16 to binary
o        Each hex digit requires 4 binary digits (i.e. n = 4)
o        Refer to the conversion table above
o        Map each digit to its equivalent binary digits = 0100 1010
= .010010102
 
·         Convert .2378 to binary
o        Each octal digit requires 3 binary digits (i.e. n = 3)
o        Refer to the conversion table above
o        Map each digit to its equivalent binary digits = 010 011 111
= .0100111112
 
·         Convert .2324 to binary
o        Each octal digit requires 2 binary digits (i.e. n = 2)
o        Refer to the base 4 to binary conversion table above
o        Map each digit to its equivalent binary digits = 10 11 10
= .1011102
 
Smaller base to Larger base conversion
·         Determine the n value
·         Construct a conversion table (i.e. counting table as seen above)
·         Group the number into groups of n digits
·         Must start grouping from the right of the fraction point (i.e. most significant fraction digit)
·         Pad with zeros if last group is less than n digits
·         Group by group, perform direct conversion using the conversion table
 
Examples
·         Convert .10112 to octal               
o        Each octal digit requires 3 binary digits (i.e. n = 3)
o        Group into 3 digits groups starting from the right of the binary point:       101 1
o        Pad bits with 0’s if less than 3 digits:               101 100
o        Map each group to its equivalent octal digit
= .548
 

·         Convert .101112 to hex


o        Each hex digit requires 4 binary digits (i.e. n = 4)
o        Group into 4 digits groups starting from the right of the binary point:       1011 1
o        Pad bits with 0’s if less than 4 digits:               1011 1000
o        Map each group to its equivalent octal digit
= .B816
 

·         Convert .101112 to base 4           


o        Each base 4 digit requires 2 binary digits (i.e. n = 2)
o        Group into 2 digits groups starting from the right of the binary point:       10 11 1
o        Pad bits with 0’s if less than 2 digits:               10 11 10
o        Map each group to its equivalent base 4 digit
= .2324

Arithmetic in different bases

·         This section discusses simple arithmetic in the different bases covering only addition and
multiplication
 
1. Addition
·         Traditional addition method is used to add two numbers
·         An Addition Table can be used to help the addition for unfamiliar bases, see tables 2.4 and 2.5 in
page 38
o        Each row or column represent an increase of 1 from the previous row or column
o        The entry at the intersection is the addition of the 2 digits
·         Addition in computer is implemented as
o        Result bit      is computed as XOR of the two input bits (i.e. result is 1 only if either digit
is 1)
o        Carry bit       is computed as AND of the two input bits (i.e. carry if both digits are 1)
 
Method
·         Use the addition table to add two digits
·         Use the traditional method of addition to add the two numbers
 
Example
·         Add 11011012 + 1001102                              = 100100112
·         Add 11011012 + 1001102 + 111111002         = 1100011112
 
2. Multiplications
·         Traditional multiplication method is used to multiply two numbers
·         A Multiplication Table can be used to help the multiplication of two digits, see tables 2.4 and 2.5
in page 38
o        Each row or column represent the addition of the value of the row or column to the
previous row or column
o        The entry at the intersection is the multiplication of the 2 digits
·         Multiplication in computer is implemented as
o        AND a multiplier digit with multiplicand
o        Bring down multiplicand if multiplier digit is 1
o        Shift result to line up with multiplier
o        Repeat for each of the multiplier digit
o        Add up the result
 
Method
·         Use the addition table to add two digits
·         Use the traditional method of multiplication that you are familiar with
 
Example
·         Multiple 11011012 x 1001102       
1101101
x        100110
---------------
     11011010
   110110100
    110110100000
      ----------------
= 10000001011102
 

·         Multiple 11112 x 1012   


1111
x        101
---------------
       1111
   111100  
      ----------------
= 10010112
 

You might also like