CSc 252 Homework 1 - Binary Arithmetic and Conversions - Prof. Homer, Study notes of Computer Architecture and Organization

Solutions to problems related to binary arithmetic and conversions from decimal to hexadecimal, octal, and two's complement for a given set of binary numbers. It covers the computation of hexadecimal and octal equivalents, decimal equivalents for signed numbers, binary addition and subtraction, and turning a given bit pattern into its decimal equivalent.

Typology: Study notes

2013/2014

Uploaded on 05/07/2014

mercy-dhanas
mercy-dhanas 🇺🇸

5

(1)

3 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSc 252 — Homework 1!Version 1.0!January 19, 2014
Solutions to Problems Turned In!
1. — Assume that 16-bit, two’s complement, binary numbers are being used in this problem.
Some binary arithmetic and conversions. For each of the pairs of numbers below, compute:!
3 points for each part. 15 points for iv, 15 points for v. 30 points for question 1.!
a.) hexadecimal (base 16) equivalents for both a and b, assume unsigned numbers!
b.) octal (base 8) equivalents for both a and b, assume unsigned numbers!
c.) decimal (base 10) equivalents for both a and b, assume signed numbers!
d.) a + b and indicate if overflow occurs, assume signed numbers!
e.) a - b by negating b and adding, indicate if overflow occurs, assume signed numbers!
iv.) turnin this one !
!a = 0110 1001 0001 1101!
!b = 0011 1010 1100 1000! !
a.) hexadecimal:!
!a = 0110 1001 0001 1101 = 69 1Dhex !
!b = 0011 1010 1100 1000 = 3A C8hex!
b.) octal!
!a = 0 110 100 100 011 101 = 64,435octal !
!b = 0 011 101 011 001 000 = 35,310octal!
c.) decimal:!
a is a positive number!
0110 1001 0001 1101 = !
214 + 213 + 211 + 28 + 24 + 23 + 22 + 20 = !
16,384 + 8,192 + 2,048 + 256 + 16 + 8 + 4 + 1 =!
1 33!
16,384!
8,192!
2,048!
256!
16!
8!
4!
1!
26,909!
26,909ten !
b is a positive number:!
0011 1010 1100 1000 =!
213 + 212 + 211 + 29 + 27 + 26 + 23 = !
8,192 + 4,096 + 2,048 + 512 + 128 + 64 + 8 = !
!
11 33!
8,192!
4,096!
2,048!
! " of " 1 8
pf3
pf4
pf5
pf8

Partial preview of the text

Download CSc 252 Homework 1 - Binary Arithmetic and Conversions - Prof. Homer and more Study notes Computer Architecture and Organization in PDF only on Docsity!

Solutions to Problems Turned In

1. — Assume that 16-bit, two’s complement, binary numbers are being used in this problem.

Some binary arithmetic and conversions. For each of the pairs of numbers below, compute:

3 points for each part. 15 points for iv, 15 points for v. 30 points for question 1.

a.) hexadecimal (base 16) equivalents for both a and b, assume unsigned numbers

b.) octal (base 8) equivalents for both a and b, assume unsigned numbers

c.) decimal (base 10) equivalents for both a and b, assume signed numbers

d.) a + b and indicate if overflow occurs, assume signed numbers

e.) a - b by negating b and adding, indicate if overflow occurs, assume signed numbers

iv.) turnin this one

a = 0110 1001 0001 1101 b = 0011 1010 1100 1000!

a.) hexadecimal:

! a = 0110 1001 0001 1101 = 69 1Dhex! ! b = 0011 1010 1100 1000 = 3A C8hex!

b.) octal

! a = 0 110 100 100 011 101 = 64,435octal! ! b = 0 011 101 011 001 000 = 35,310octal!

c.) decimal:

a is a positive number

26,909ten!

b is a positive number:

15,048ten!

d.) a + b

1010 0011 1110 0101 overflow!

When adding a positive to a positive, the answer should be positive. Since this answer

came out negative, there was overflow.

e.) a - b

! a = 0110 1001 0001 1101! ! b = 0011 1010 1100 1000!

Find the two's complement of b, then add.

Two’s complement of b:

1100 0101 0011 0111 Invert step!

  • 1 add 1! 1100 0101 0011 1000

Now, add a and the two’s complement of b:

0010 1110 0101 0101 no overflow

Positive - Positive can never produce overflow.

v.) turnin this one

! a = 1011 0011 1110 0110! b = 1100 1010 0101 1000!

! a.) hexadecimal

a = 1011 0011 1110 0110 = B3 E6hex! b = 1100 1010 0101 1000 = CA (^58) hex

b.) octal

a = 1 011 001 111 100 110 = 131,746octal b = 1 100 101 001 011 000 = 145,130octal

c.) decimal

a is a negative number; find two’s complement first:

0100 1100 0001 1001 Invert step!

  • 1 add 1!

Now, add a and the two’s complement of b:!

1110 1001 1000 1110 no overflow.

When subtracting negative - negative, overflow is not possible.

5. turnin this one (15 points, 5 points each part) — This exercise is similar to the

previous one, but this time, use the bit pattern:

What does it represent, assuming that it is

a.) a two’s complement integer?

b.) an unsigned integer?

c.) a single precision floating-point number?

d.) four ascii characters?

a.) The sign bit is 1 , so this is a negative number. Start by finding the two’s complement:

0011 0110 1000 1100 1001 0100 1001 1110 invert step!

  • 1! 0011 0110 1000 1100 1001 0100 1001 1111!

Answer:! -915,182,751 (^) ten!

b.) Assume an unsigned number:

Answer:! 3,379,784,545 (^) ten!

c.)! S Expo nent Sig nifi cand! 1 1001 0001 111 0011 1110 1011 0110 0001! 1 1001 0010 111 0011 0110 1011 0110 0001 new!

S = 1, a negative number!

Exponent = 1001 0010 = 27 + 24 + 20 = 128 + 16 + 2 = 146!

11,342ten = 10 1100 0100 1110two

Convert the fractional part to a binary number. Do this by subtracting successive negative

powers of two. When the number cannot be subtracted, put a 0 in. When the number can

be subtracted, put in a 1.

- 0.5 2 -1^!

2 -2^ is 0.25 and is too large. Put in 0

2 -3^ is 0.125 and is too large. Put in 0.

Subtract 2-4:

- 0.0625 2 -4^!

Subtract 2-5:

- 0.03125 2 -5^!

Subtract 2-6:

- 0.015625 2 -6^!

0.0 done!!

The fraction part is 0.

The binary equivalent is 10 1100 0100 1110.100111 =

sign is 1, since the number is negative! exponent = 13 + 127 = 140 = 1000 1100! significand = 011 0001 0011 1010 0111! ! S Expo nent Sig nifi cand! 1 1000 1100 011 0001 0011 1010 0111 0000!

b.)

There are two differences between single- and double-precision:

The exponent uses 11 digits and a bias of 1,023.

There are more digits in the significand.

To convert the exponent:

subtract the bias: 140 - 127 = 13

Now, use a bias of 1,023:

The result is:

S Exp onen t Significand! 1 100 0000 1100 0110 0010 0111 0100 1110 0000 0000! 0000 0000 0000 0000 0000 0000!