CSC 205 Introduction to Computer Science
Assignment #6
Using the Spreadsheet to Explore Binary Conversions
Objectives
- Learn the meanings of the following terms:
Base 2, Byte, Digits
- Gain practice using the spreadsheet as a mathematical tool to do calculations that would be tedious by hand.
- Gain more practice using formulas and fill-down in the spreadsheet.
- Learn how to use the conditional function, IF, in the spreadsheet.
- Learn how to use one of the rounding functions, ROUNDDOWN, in the spreadsheet.
- Learn more about the Base 2 Number System.
- Gain more practice with binary expansions by converting decimal to binary and binary to decimal.
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.
- Showing your work, convert the following binary numbers to decimal:
- 111112
- 1011012
- 11000112
- 1012
- 0.112
- 101.112
- 10102
- 101002
- 1010002
- 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.
- In cell A1 type 43.
- Use Excel's Office Assistant to read about the ROUNDDOWN function, and in cell A2 enter
a formula which will take whatever number is in cell A1, divide it by 2, and keep only the
whole part of the number. When you have a correct formula entered, push return.
The number 21 should appear in cell A2. Write the formula you used for A2 in your Word document.
- In the above procedure for finding the binary representation, the important part is really
the remainder, so we will now calculate the remainders of our divisions by 2 in column B.
- To calculate the remainders, we need to test whether or not 2 went into A1 evenly.
We will use the IF function to do this test for us and to output the correct remainders.
Type a formula using IF into cell B2 which tests to see if what is in A2 is exactly equal to
what is in A1 divided by 2. If it is equal then there was no remainder, so the output should be 0.
Otherwise, there is a remainder and the output should be 1. When you have this formula entered,
push return. The number 1 should appear in cell B2. Write the formula you used for B2 in your Word document.
- When you have these formulas correct, fill down columns A and B, stopping when you get to 0 in column A.
- Reading Column B backwards should give the binary representation of whatever is in cell A1!
- Test your formulas by trying some other numbers for which you know the binary representation.
Work and Questions Part II
Continue your Word file, writing answers to the following:
- 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?
- Convert the following decimal numbers to binary by hand, showing your work:
- 47
- 358
- 1023
- Use your spreadsheet check your work by converting the following decimal
numbers to binary:
- 47
- 358
- 1023
- Use your spreadsheet to find the binary representation for the decimal number
96,455. Is the binary expansion longer (or shorter) than you expected?
- Deterine whether or not your spreadsheet algorithm works for negative whole
numbers. Explain.
- Use your spreadsheet to convert the following Decimal Numbers to Binary:
- 1
- 3
- 7
- 15
- 31
- 63
- Use Exercise 6 to find a rule which describes all numbers that have a binary
representation consisting solely of 1's.
- 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.
- 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.
- 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.
- 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...
- Those who understand binary...
- And those who do not...
:)
Back to
Introduction to Computer Science