Lab #2 Questions - Western Oregon University

advertisement

CS-160 Lab #2, Name:

Assignment Instructions

Answer the following questions. Please copy and paste the questions below into your editor and TYPE your answers below each question. You may include pictures, diagrams, as needed.

You can hand draw your diagrams (neatly) and scan them or photo them with your phone and then paste the picture into this document. TURN IN ONLY THIS DOCUMENT , we will not look at or grade additional documents or separate pictures unless you are told to do so in the assignment. Optional challenge questions are just for your own learning; they do not count toward grading; we do not give extra credit in this class.

Binary Number Representations:

In all of the questions below, binary refers to base 2 numbers, hex refers to base 16 numbers, and decimal refers to base 10 numbers.

Q1: Look for a relationship between the binary representations (you can use one of the practice applets to convert these) of 17, 34, and 68. The same relationship should hold between the binary representations of 22, 44, and 88. a) What is the relationship? b) What is the equivalent relationship in the decimal system?

Q2: For the DECIMAL (base 10) value 100: a) How many bits are there in the binary representation? b) What is the largest decimal number you can represent with that number of bits?

Q3: Convert the decimal numbers 14 and 49 into their 8-Bit binary equivalents using the first method described above (greatest power of 2 less than or equal to the number). SHOW

YOUR WORK THAT DOES THE CONVERSION! a) Answer for 14: b) Answer for 49:

Q4: Convert the decimal numbers 19 and 57 into their 8-Bit binary equivalents using the second method described above (successive divisions by 2). SHOW YOUR WORK THAT

DOES THE CONVERSION! a) Answer for 19: b) Answer for 57:

Q5: Using your favorite method, convert the decimal numbers 161 and 221 into their 8-Bit binary equivalents. a) Answer for 161: b) Answer for 221:

Western Oregon University Page

1

of

5

CS-160 Lab #2, Name:

Q6: Convert each of the following binary numbers into their decimal equivalent. a) Binary: 1011000110 Decimal value: ? b) Binary: 1100101101110 c) Binary: 10000001111

Decimal value: ?

Decimal value: ?

Hexadecimal, Decimal, Binary Conversions

Q7: Convert the following hexadecimal unsigned integers to their decimal equivalents: a) 20A Answer: b) F39 Answer: c) 1552 Answer:

Q8: Convert the following decimal integers to their equivalents in the hexadecimal number system: a) 161 Answer: b) 2576 Answer: c) 3501 Answer: d) 64180 Answer:

Q9: Convert the following binary unsigned integers to their equivalents in the hexadecimal number system: a) 10010110 Answer: b) 01011100 Answer: c) 11111111 Answer: d) 00000000 Answer:

Q10: Why is it that 4 binary digits can be represented by on single hexadecimal digit?

Answer:

Western Oregon University Page

2

of

5

CS-160 Lab #2, Name:

Optional Challenge Question: What is the largest integer that can be represented by…

1) Two binary digits (2 bits)?

2) Two octal digits?

3) Two decimal digits?

4) Two hexadecimal digits?

5) Two digits from a base-k number system? (use a mathematical formula to represent this)

Unsigned Binary Addition

Q11: Calculate the sum of the following 8-bit binary numbers. You should line up the numbers in columns, and show the carry operations that occur (the subscript indicates that these are base-2/binary numbers)

Example for

0001 1010

2

+ 0001 1010

2

11 1 carry

0001 1010

+ 0001 1010

0011 0100 a)

Answer:

0000 0101

2

+ 0000 1110

2 b)

Answer:

0001 0000

2

+ 0011 1100

2 c)

Answer:

0000 1110

2

+ 0001 0010

2

Two’s Complement

Q12: Convert the following 6-bit, two’s complement integers to their decimal equivalents: a) 111111 Answer: b) 100000 Answer: c) 101010 Answer: d) 010101 Answer:

Western Oregon University Page

3

of

5

CS-160 Lab #2, Name:

Q13: Convert the following decimal integers to their equivalents in 6-bit, two’s complement binary numbers: a) -16 Answer: b) -8 c) -4

Answer:

Answer: d) 4 e) 8

Answer:

Answer: f) 16 Answer:

Q14: In your own words and based on evidence (meaning to show an example!), explain what happens when you negate the negation (take the negative of a negative) of a number in two’s complement notation. Start with a positive binary number, then find it’s two’s complement representation, and then apply the same process again to the 2’s complement number (the 2’s complement of a 2’s complement number). Show your work at each step.

Answer:

Q15: Calculate the sum of the following 6-bit, two’s complement binary numbers. You should line up the numbers in columns, and show the carry operations that occur. Label the each answer with OVERFLOW or NO OVERFLOW

Example for 111010

2

+ 011010

2 your answer would be:

11 1 carry

111010

+011010

010100 NO OVERFLOW a) 100101

2

+ 001110

2

Answer: b) 100100

2

+ 100001

2

Answer: c) 011110

2

+ 010001

2

Answer:

Western Oregon University Page

4

of

5

CS-160 Lab #2, Name:

Q16: For 2 6-bit 2’s Complement values, what numbers that when added together, have the

FEWEST total number of bits with a value of 1 that will still cause an overflow?

Q17: For 2 6-bit 2’s Complement values, what numbers that when added together, have the

LARGEST total number of bits with a value of 1 that doesn’t cause overflow?

Q18: For 2 6-bit 2’s Complement values, describe the situations where the overflow bit set for addition of two numbers (i.e. what types of integers being added together will cause overflow to occur)? Add several numbers together and observe the result. Hint: for 2’s complement addition, a number overflow is not always indicated by the value of the leftmost carry bit (this is different from unsigned binary addition).

Western Oregon University Page

5

of

5

Download