Horner’s Rule
Horner’s rule is an efficient algorithm for converting a number
written in base b into its decimal notation.
Horner’s rule is also useful for evaluating a polynomial, and Taylor
coefficients.
Evaluating polynomials by Horner’s rule is covered elsewhere in
this course.
Horner’s Rule
Consider the natural number 43. Writing 43 as a sum of powers
of 2 implies its binary representation.
43 = 32 + 8 + 2 + 1
43 = 1 · 25 + 0 · 24 + 1 · 23 + 0 · 22 + 1 · 21 + 1 · 20
43 = (10 1011)2
Horner’s rule writes converts (10 1011)2 to 43 from the most sig-
nificant bit to the least significant bit.
43 = (((((1 · 2) + 0) · 2 + 1) · 2 + 0) · 2 + 1)
This multiplicity of parentheses is somewhat confusing, so let’s re-
formulate it.
Horner’s Rule to Convert Binary to Decimal
To convert (10 1011)2 to decimal:
1. write the bit pattern to be converted (leave sufficient space
between bits)
1 0 1 0 1 1
2. Next, bring down the leading 1
1 0 1 0 1 1
(Continued next slide)
1
Example Continued
Continuing from the previous slide.
3. Multiply the 1 by 2 and place it under the next bit.
1 0 1 0 1 1
2
1
4. Add the values in the second column.
1 0 1 0 1 1
2
1 2
5. Repeat the process.
Example Continued
Continuing from the previous slides.
Multiply 2 by 2 and add 1.
1 0 1 0 1 1
2 4
1 2 5
Multiply 5 by 2 and add 0.
1 0 1 0 1 1
2 4 10
1 2 5 10
2
Example Continued
Continuing from the previous slides.
Multiply 10 by 2 and add to 1.
1 0 1 0 1 1
2 4 10 20
1 2 5 10 21
Multiply 21 by 2 and add 1.
1 0 1 0 1 1
2 4 10 20 42
1 2 5 10 21 43
Therefore, (10 1011)2 = 43.
Other Examples of Binary to Decimal Conversion
Here’s an example computation of Horner’s rule to convert bi-
nary (1101 0100)2 to decimal 212.
Horner’s Rule
1 1 0 1 0 1 0 0
2 6 12 26 52 106 212
1 3 6 13 26 53 106 212
And here is a second example.
Horner’s Rule
1 0 0 0 1 1 1 1
2 4 8 16 34 70 142
1 2 4 8 17 35 71 143
Therefore, (1000 1111)2 = 143.
3
Converting Ternary to Decimal
You can also use Horner’s rule convert from bases other than 2
to decimal.
Here’s an example computation of Horner’s rule to convert
ternary (210)3 to decimal 21.
Horner’s Rule base=3
2 1 0
6 21
2 7 21
Converting Hexadecimal to Decimal
Here’s an example computation of Horner’s rule to convert hex-
adecimal (CAFE)16 to decimal 51966.
Horner’s Rule base=16
C A F E
192 3232 51952
12 202 3247 51966
Because ( DEAD CODE)16 is an interesting string you might want
to convert it to decimal.