2012 April 16,

CS 111: Assignment: Binary

Carleton College, Spring 2012

Prof. Joshua R. Davis, , Goodsell 106B, x4473

This assignment helps you practice with the concepts introduced in the Binary tutorial. We covered most of it in class, but you should read through it for the parts that we missed. You are allowed to work through the assignment with other students, but each student must submit his/her own solutions individually, on paper. Show all of your work. If you use multiple pages, then they must be stapled — not paper-clipped or loose. The assignment is due Friday at the start of class.

A. Find the 32-bit binary numeral corresponding to 1234. Also, find the 32-bit expansion of the string "1234", regarding each character as an 8-bit numeral according to ASCII. (This question is intended to emphasize that the integer 1234 and the string "1234" are represented by completely different 32-bit words.)

B. Add 00100011001000012 and 01001001111011112.

C. Multiply 000011012 and 000001102.

D. Overflow errors happen more frequently in multiplication than in addition, because the product of two integers is usually much larger than their sum. In unsigned 8-bit binary, how big can the two numbers be, before their product overflows? Give me a rule of the form "As long as the two numbers being multiplied are no longer than ____ bits, their product will not overflow."

E. Compute the difference 98 - 114 in 8-bit two's complement (by using negation and addition).

F. Give an example of how the rule a - b = a + -b fails in the 4-bit sign bit system. That is, find two 4-bit numerals that, when interpreted as signed integers according to the sign bit system, violate the rule (and demonstrate that they violate it).

G. In floating-point numbers, why does the first digit of the significand (the digit before the ".") not need to be stored?

H. Express "orange, halfway between transparent and opaque" as a 32-bit RGBA color, in hexadecimal.