CSC 205 Introduction to Computer Science

Assignment #6
Using the Spreadsheet to Explore Binary Conversions


Objectives


The Decimal Number System

In order to better understand the binary number system that computers use as their primary number system, we will first discuss the decimal system that we use daily because both of these systems are based upon the idea of place value.

Believe it or not, our decimal counting system is based on the number ten because we have ten fingers. (This is why we sometimes call numerals digits, just like we call our fingers digits.) The main principle of the decimal system is that the numbers 0 through 9 are simply represented by their own digits (in a position called the 1's place, since these digits just represent themselves multiplied by 1.) The number 10 is considered as a new unit from which point counting starts over again. This is represented by putting a numeral in the "place" to the left of the 1's "place, " and any digits here represent themselves times 10. Then 10 more 10s is again a new unit, and each "place" to the left represents an additional multiple of 10.

This way of counting is old. Indo-European languages, which are spoken from India to Europe, all have the same counting system as well as very similar words for numbers. We can conclude that the basic Indo-European mother language had a similar same method of counting - called decimal counting as early as 3000 BC. Though, origins of the decimal counting system are somewhat hidden, we can imagine the spread of this system through trade routes.

The decimal number system is the base 10 number system that we know and use. It uses ten different digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 to represent numbers. It is a place value system which means that each place represents a power of 10 like so:

Place Value . . . 104 103 102 101 100 . 10-1 10-2 . . .
Decimal Value: 10000 1000 100 10 1 0.1 0.01
Thus, a decimal number such as 10,574 = 1 x 104 + 0 x 103 + 5 x 102 + 7 x 101+ 4 x 100.


The Binary Number System

Every number that can be written in decimal can also be written in another system called binary. Binary is the number system used by computers, because modern computers system are made up of electric circuits. These circuits carry two electric states, a low voltage and a high voltage. The voltages are manipulated so that the computer can do something of use, and the binary number system is well suited for this manipulation because it is a two state number system. This system can be use as a model of the computer's circuit's with a '0' representing a low voltage and a '1' as a high voltage. By manipulating the circuits of the computer system to behave like the binary number system, the computer is able to perform calculations, the bases of all it's operation.

The binary number system is a base 2 number system which uses only the two digits 0 and 1. It is also a place value system which means that each place represents a power of 2, just as the place represents a power of 10 in the decimal system:

Place Value . . . 27 26 25 24 23 22 21 20 . 2-1 2-2 . . .
Decimal Value: 128 64 32 16 8 4 2 1 0.5 0.25

Every BInary digiT is called a bit which is either a 0 or a 1. An 8 bit number is called a byte inside a computer.

4-bit binary decimal
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
4-bit binary / decimal table

A binary number such as 11010010 can be rewritten in decimal by using the place value:
11010010 = 1 x 27 + 1 x 26+ 0 x 25 +1 x 24 + 0 x 23 + 0 x 22 + 1 x 21+ 0 x 20.


Converting Binary to Decimal

To convert a binary number to decimal, add up all the decimal values of the non-zero bits.

Example: Convert the binary number 11010010 to decimal.

First, write out a table, including the binary number to be converted:
27
26 25 24 23 22 21 20
Decimal Value: 128 64 32 16 8 4 2 1
1 1 0 1 0 0 1 0

Next add the decimal values:
11010010 = 1 x 27 + 1 x 26+ 0 x 25 +1 x 24 + 0 x 23 + 0 x 22 + 1 x 21+ 0 x 20
= 128 + 64 + 16 + 2 = 210

Answer: 110100102 = 21010
(Here the little 2 means base 2 and the little 10 means base 10.)

Work and Questions Part I

This assignment may be done alone or in a group, but you may find it preferable to work in a group. Turn in your answers to all of the following questions typed in a Microsoft Word document named YourLastNameBinary. Feel free to check your work with your laptop's scientific calculator.

  1. Showing your work, convert the following binary numbers to decimal:
    1. 111112
    2. 1011012
    3. 11000112
    4. 1012
    5. 0.112
    6. 101.112
    7. 10102
    8. 101002
    9. 1010002

  2. Looking at your workin in 1g-h, in general, if B is some binary number (such as 10102), what number do you get when you attach a zero at the right end (such as 101002). What number do you get when you attach 2 zeros at the right end? In general, what number do you get when you attach n zeros at the right end?

In the next part of this assignment, we will use the spreadsheet's calculation power to help us to convert decimal numbers to binary numbers. You will write the resulting formulas in your Word document. Let's review binary and the conversion process of whole numbers.

Converting Decimal to Binary

Converting Whole Decimal Numbers to Binary
To convert a whole decimal number to binary, divide the non-fractional decimal number by 2 repeatedly until you get a quotient of 0, keeping the remainders of each division. Write the remainders after each step of division (which will either be 1 or 0) off to the side. Finally, when no more division be done, write down the remainders in reverse order (with the last remainder written first). This is the converted binary number.

Example: Represent 43 (decimal) in binary.

43 / 2 = 21 Remainder = 1
21 / 2 = 10 Remainder = 1
10 / 2 = 5 Remainder = 0
5 / 2 = 2 Remainder = 1
2 / 2 = 1 Remainder = 0
1 / 2 = 0 Remainder = 1
We are done since we have reached 0.
Taking remainders in reverse order, we have 1010112
which is the binary representation of 43 because 43 = 32+8 + 2 + 1= 1 x 25 + 0 x 24+ 1 x 23 + 0 x 22 + 1 x 21+ 1 x 20.
Answer: 4310 = 1010112

(Again, the little 10 means base 10 and the little 2 means base 2.)

Converting Fractional Decimal Numbers to Binary
To convert a fractional decimal number (which must me less than 1) to binary, multiply the fractional decimal number by 2 repeatedly until you get 0, keeping the whole numbers of each multiplication. Subtract the whole number off and keep only the fractional part, but write the whole numbers after each step of multiplication (which will either be 1 or 0 off) to the side. Finally, when no more multiplication can be done, write down the whole numbers in forward order (with the first whole number written first). This is the converted binary number.

Example: Represent 0.781252 in binary.

0.78125 * 2 = 1.5625 whole number = 1 fractional part=0.5625
0.5625 * 2 = 1.125 whole number = 1 fractional part=0.125
0.125 * 2 = 0.25 whole number = 0 fractional part=0.25
0.25 * 2 = 0.5 whole number = 0 fractional part=0.5
0.5 * 2 = 1 whole number = 1 fractional part=0
We are done since there is no more fractional part left.

Taking the whole numbers in the forward order, we have 0.110012
which is the binary representation of 0.78125 because 0.78125 = 0.5 + 0.25 + 0.03125= 1 x 2-1 + 1 x 2-2 + 0 x 2-3 + 0 x 2-4+ 1 x 2-5.

Answer: 0.7812510 = 0.110012


Building a Spreadsheet Number Converter

Now we will build a spreadsheet tool to help us to convert whole decimal numbers into binary. Open Excel and begin a new worksheet.


Work and Questions Part II

Continue your Word file, writing answers to the following:

  1. Try using your spreadsheet for conversions by putting 100 into A1. What does your spreadsheet find for the binary representation for 100? Is this the same as your scientific calculator's answer?

  2. Convert the following decimal numbers to binary by hand, showing your work:
    1. 47
    2. 358
    3. 1023

  3. Use your spreadsheet check your work by converting the following decimal numbers to binary:
    1. 47
    2. 358
    3. 1023

  4. Use your spreadsheet to find the binary representation for the decimal number 96,455. Is the binary expansion longer (or shorter) than you expected?
  5. Deterine whether or not your spreadsheet algorithm works for negative whole numbers. Explain.
  6. Use your spreadsheet to convert the following Decimal Numbers to Binary:
    1. 1
    2. 3
    3. 7
    4. 15
    5. 31
    6. 63

  7. Use Exercise 6 to find a rule which describes all numbers that have a binary representation consisting solely of 1's.
  8. The decimal expansion of 11/16 is 0.6875. Find the binary expansion of the fraction 11/16. Do not stop until you are certain you know the EXACT expansion.
  9. The decimal expansion of 3/10 is 0.3. Find the binary expansion of the fraction 3/10. Do not stop until you are certain you know the EXACT expansion.
  10. Read over the algorithm for converting a whole decimal number to binary. Then think about the meaning of a binary number using it's place value representation. Consider why you think this algorithm works. Then using the ideas of place value, write a detailed explanation as though you were wanting to convince someone that this algorithm will really give you the binary representation of the decimal number. Be sure to address what in the heck the remainders have to do with anything. You may want to discuss this with classmates to polish your explanation.
  11. Put your name(s) and "Binary Conversions" in the header of the Word document, name the Word file yourusernameA6 and the Excel file yourusernameA6, and turn both in by dropping theminto the "A6 Binary" dropbox.

Some people say that there are only 10 kinds of people in the world...

:)


Back to Introduction to Computer Science