CS 130 Lab #2: Operations on Binary Numerals

This lab is short, like the last one, but is more focused on technical issues and will probably be more challenging, at least for some students.

Due date: please have your answers to the questions below available by the end of lab on Monday 6 February.

Generating "your" numbers

In this lab we will be doing various conversions and transformations on numbers; in order to encourage students to do their own work (the practice that the lab provides is only worthwhile if you do it yourself!), we will need some unique numbers that "belong" to you, numbers that no one else in the class is likely to have.

We will therefore use your name and birthdate to generate some numbers that are uniquely yours: let's call them your "small number" and your "large number":

Some resources and tools for binary numeral calculation

These are just repeats from the course homepage, for your convenience here in the lab write-up:

Addition of binary numerals

Convert your large and small numbers into binary notation using the techniques from lecture. (You may check your work using a calculator or on-line tool, but I recommend doing the work itself by hand, since you won't have access to these tools on quizzes and exams.)
(Yes, yes, the large number in particular will no doubt involve an annoyingly large number of binary digits. But one of the hidden purposes behind this lab is to motivate ways of "abbreviating" large binary numbers so that they can be written and remembered more efficiently, but also easily converted back to their original binary form.)
Now add the two numbers together, in binary, being careful to show all your work in the tabular format usual for addition (i.e., numbers right-aligned, digits in columns, "carries" shown in the usual way, etc.). Be prepared to show this work during your demo, and perhaps to do some more binary addition "live".

If you have trouble adding the two numbers together, look again at the reference material above. Remember that it's just like adding numbers in decimal, working place by place from right to left, except there are fewer cases to handle:

Multiplication of binary numerals

How do we multiply numbers in decimal? There is a popular method (or algorithm) called "long multiplication" which you probably learned in grade school: it uses a fixed layout for the numbers, a few lines and some simple rules.

We lay out two numbers, one above the other, aligning their digits so that they are flush to the right. We then proceed through the digits of the lower number from right to left. For each digit, we multiply this digit by the upper number, and write it down below the line, remembering to move the result one place to the left each time. Now we add the columns of digits together, writing down the rightmost digit of the result and carrying any other digits into the next column:

Multiplying binary numbers is almost the same, except easier:

Special cases

Multiply your large number by eight, using decimal notation, by hand. Note the steps that you use, the carries, etc., that make the task at least a bit bothersome. Now take the converted binary version of your large number and multiply it by eight, using the binary version of the technique. What do you notice when you compare the original number and the result, i.e., how are they related (in the simplest terms)?

What you need for your demo