Beruflich Dokumente
Kultur Dokumente
Background
Integer Conversion
· 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
· 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