=================================================
Assignment #04 - Number Systems with Negative Numbers
=================================================
- Ian! D. Allen - idallen@idallen.ca - www.idallen.com
Available online: Tuesday February 2, 2010
Upload due date in the Blackboard Assignment Area:
Upload "assignment04.txt" before 13:00 (1 pm) on Tuesday February 9, 2010
Do *not* use the DigitalDropbox to submit your answers.
Answers will be posted shortly after the due date/time.
Submission method: Upload via the "Assignments" CST8281_Assignment_04 upload.
Use the file name given above. Upload only one single file of plain
text, not HTML, not MSWord, not RTF. No fonts, no word-processing.
Plain text only. Did I mention that the format is plain text (Notepad)?
Due to bugs in Blackboard, you can only submit your Assignment to
me *once*. After that, you cannot submit any more times. If you need
to re-submit it, you have to email me to ask me to clear your previous
submission. Do *not* use the DigitalDropbox to submit your answers.
Answers will be posted after the due date/time so that you can check
your answers before coming to labs and ask questions about the answers
in the labs. Please check your answers (and my answers!). I go over
each assignment in the lab if there are questions about the answers.
No questions means no review - I'll presume you know the material.
Questions similar to ones on these assignments will appear on your tests
and exams.
Not all assignments will be marked. See the Week 1 Notes for details.
==============================================================================
Edit this file and answer the following questions underneath each
question, showing how you obtained each answer. Answers without methods
are worth zero.
The point of the conversions is not to show me the answer. I already
give you many of the answers. The point is to show me that you have a
clear *method* for getting that answer that works for you.
You must show me a clear method that turns the decimal into binary, and
vice-versa. The method must work for any number. Show me your method.
The point of the conversions is not to show me that you can do the
question backwards and convert the binary back to decimal by adding up
powers of two in the answer. Your tests and exams won't have any answers.
I asked you to convert the decimal to binary, not the other way around.
Upload the file containing the methods and the answers before the
due date. Some of the answers below may require reading the URL links
published in the weekly notes.
Practice:
Write down any three-digit decimal number (e.g. -314).
Convert it to two's complement binary using your method.
Check your work on the Internet, using a decimal-to-binary
conversion web page. Google search: decimal to binary conversion
Sample conversion site:
http://acc6.its.brooklyn.cuny.edu/~gurwitz/core5/nav2tool.html
Quiz site:
http://acc6.its.brooklyn.cuny.edu/~gurwitz/core5/binquiz.html
Subtraction method (with pictures!):
http://www.is.wayne.edu/olmt/binary/page3.htm
You can check your work using any online converter; use Google to find one.
e.g. http://www.tonymarston.net/php-mysql/converter.php
==============================================================================
1. Using a word size of four bits, list in order vertically all of the
possible bit patterns from 0000(2) to 1111(2). Beside each of the 16
patterns, give:
a) the hexadecimal and unsigned decimal equivalent
b) the four-bit signed-magnitude decimal equivalent
c) the four-bit one's complement decimal equivalent
d) the four-bit two's complement decimal equivalent
2. What are the largest and smallest integers (in decimal) an 8-bit word
can hold using a sign-magnitude representation?
3. What are the largest and smallest integers (in decimal) an 8-bit word
can hold using a one's complement representation?
4. What are the largest and smallest integers (in decimal) an 8-bit word
can hold using a two's complement representation?
5. What are the largest and smallest integers a 16-bit word can hold
using a sign-magnitude representation?
6. What are the largest and smallest integers a 16-bit word can hold
using a one's complement representation?
7. What are the largest and smallest integers a 16-bit word can hold
using a two's complement representation?
8. Generalize the above answers: For an N-bit word size, express as a
formula using N as a power of two (i.e. using 2**N) what are the largest
(most positive) and smallest (least positive) integers possible for:
a) N-bit unsigned
b) N-bit signed-magnitude
c) N-bit one's complement
d) N-bit two's complement
9. Convert 23 to 8-bit 00010111 binary one's complement.
10. Convert -9 to 8-bit 11110110 binary one's complement.
11. Convert -23 to 8-bit 11101000 binary one's complement.
12. How do you know that a two's-complement addition has overflowed?
(There are at least two ways. Give one or both.)
13. Convert 23 to 8-bit 00010111 binary two's complement.
14. Convert -9 to 8-bit 11110111 binary two's complement.
15. Convert -23 to 8-bit 11101001 binary two's complement.
16. Convert 8-bit 10010011 binary sign-magnitude to -19 decimal (note
the negative).
17. Convert 8-bit 10010011 binary one's complement to -108 decimal (note
the negative).
18. Convert 8-bit 10010011 binary two's complement to -109 decimal (note
the negative).
19. Copy the left column of ECOA2e Chapter 2 slide 54. Fix the second sum
to be 0100+0110. Perform the given two's complement additions.
Without looking, fill in the remaining four columns based on the
results. Add another column that states whether the result is
correct if treated as unsigned math instead of two's complement.
20. Convert 16-bit two's complement 8000h to decimal -32,768 (note the
negative).
21. Convert 16-bit two's complement A123h to decimal -24,285 (note the
negative).
22. Convert 16-bit two's complement FFFFh to decimal -1 (note the negative).
23. Cross out or delete the positive numbers (16-bit two's complement),
leaving only negative numbers: 8000h 8001h 9FC5h A123h BFFFh
24. Add 16-bit two's complement ABCDh to 7FFFh and give the Result, Carry,
Overflow, and Sign. Is the result correct?
25. Add 16-bit two's complement 8A9Ch to ABCDh and give the Result, Carry,
Overflow, and Sign. Is the result correct?
26. Add 18-bit two's complement 8A9Ch to ABCDh and give the Result, Carry,
Overflow, and Sign. Is the result correct? (18 is not a mistake)
27. Add 16-bit two's complement 9999h to 4321h and give the Result, Carry,
Overflow, and Sign. Is the result correct?
28. Is it still true that shifting a binary number left one bit multiplies
it by two, if the number is a negative two's complement number?
29. Cross out or delete the following positive values that will fit
correctly in a 32bit two's complement integer with no misrepresentation
(leave behind only the values that *cannot* be correctly converted):
(2**29)-1 2**29 (2**29)+1
(2**30)-1 2**30 (2**30)+1
(2**31)-1 2**31 (2**31)+1
(2**32)-1 2**32 (2**32)+1
(2**33)-1 2**33 (2**33)+1
(2**30)+(2**29) (2**30)+(2**29)+(2**3)+(2**2)+(2**1)
30. Build a Truth Table for two's complement "overflow", based on the rule
that overflow occurs if the carry in to the sign bit does not equal the
carry out. Use these headings on the truth table columns:
------------ -------------
A B CI R CO OV
------------ -------------
Columns A, B, and CI are inputs. R, CO, and OV are outputs. Columns A
and B are the sign bits of the two numbers being added. Column CI is
the possible carry in to the sign bit. CO (carry out), R (result), and
OV (overflow flag) are outputs. The truth table must have eight rows,
for all possible combinations of the three inputs A, B, and CI. R is
the sign bit of the result (based on A, B, and CI). CO is the carry out
(also based on A, B, and CI). OV is whether or not overflow occurred
(based on CI and CO). Fill in the whole 8x6 table.
--
| Ian! D. Allen - idallen@idallen.ca - Ottawa, Ontario, Canada
| Home Page: http://idallen.com/ Contact Improv: http://contactimprov.ca/
| College professor (Free/Libre GNU+Linux) at: http://teaching.idallen.com/
| Defend digital freedom: http://eff.org/ and have fun: http://fools.ca/