HW3 Solutions

HW3 Solutions - CSc 445: Homework 3 Solutions March 3, 2008...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSc 445: Homework 3 Solutions March 3, 2008 1. Negabinary arithmetic.. Solution a We can use the division method for converting decimal to binary. Here are the steps: Step 1 Divide the current number by -2, write the remainder 0 or 1 on one side. Step 2 Make the quotient the next number and repeat step 1. Step 3 Stop when the quotient is 0 or 1. Step 4 Collect all the remainders in reverse. These numbers seen together represent the base -2 equivalent. The above process works because, we are recursively peeling away a factor of -2 at each step and collecting the remainder which happens to be either 0 or 1. i.e., N = ∑ ≤ i ≤ n- 1 a i * (- 2) i = a * (- 2) + a 1 * (- 2) 1 + a 2 * (- 2) 2 + .. . + a n- 1 (- 2) n- 1 = a * (- 2) + (- 2) * { a 1 + a 2 * (- 2) 1 + .. . + a n- 1 (- 2) n- 2 } where each a i ∈ { , 1 } , ≤ i ≤ n- 1 Solution b We can use weak induction to prove this as follows: Base Case The base case is for a -2 base number with 2 bits: 00, 01, 10, 11 all represent different numbers. Hypothesis Each permutation of k bits uniquely represents some number. This is proved for a pattern that is k + 1 bits long by noticing that each unique number (by IH) represented by the k Least Significant Bits will be added with (- 2) k if the k + 1 th bit is 1. Otherwise, if the bit is 0, the number is still unique among all other k +1 permutations of 0s and 1s. Solution c The rules for addition and subtraction are described next. These are repeated verbatim from the paper Arithmetic Algorithms in a Negative Base, Sankar et al. IEEE Transactions on Computers, Vol 22 Issue 2 pp 120-125 1973 . For two numbers a and b in base- β a = ∑ ≤ i ≤ m a i * (- β ) i b = ∑ ≤ i ≤ n b i * (- β ) i The sum a + b is a + b = ∑ ≤ i ≤ max m,n +2 s i * (- β ) i where s i is defined by the following table. There are two carry digits c * and d * for 1 this addition. The movitation for two digits may be obtained by observing that -1 in base -2 is represented as a pair of digits. Cases c i d i +1 a i + b i + c i s i c i +1 d i +2 ≥ 2 β a ( β- 1) 1 1 ( β- 1) 1 ≥ β ( a i + b i + c i ) mod β < β 1 ≥ β ( β- 1) 1 2 0 or 1 ( a i + b i + c i ) mod β < β Note: a This case ( a i + b i + c i ) ≥ 2 β is not possible for base -2, since the only car- ries possible are 0, 1 and 11. Solution d Now the negative of a number can be represented as follows: Let a be the given number and a be the polarized form. Consider a = m X i =0 a i (- β ) i The above can be manipulated as follows: a =- (- β ) m +1 + ∑ m i =1 (- β ) i ( β + 1- a i ) + ( β- a ) =- a where a = ∑ m +1 i =0 a i (- β ) i The rules for negating a general number can now be given as follows: Rule 1 If a i / ∈ 0, 1 ∀ i , then a = ( β- a ); a i = ( β +1- a i ) for 1 ≤ i ≤ m , and a m +1 =1....
View Full Document

This homework help was uploaded on 04/08/2008 for the course CSC 445 taught by Professor Kobourov during the Spring '08 term at Arizona.

Page1 / 11

HW3 Solutions - CSc 445: Homework 3 Solutions March 3, 2008...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online