Skip to main content

Exercises 1.31-1.60

All Exercises

Exercise 1.31 Convert the following decimal numbers to 8-bit sign/magnitude numbers or indicate that the decimal number would overflow the range

a) 4210

b) −6310

c) 12410

d) −12810

e) 13310

Solution:

a) 4210 = 1x32(25) + 0x16(24) + 1x8(23) + 0x4(22) + 1x2(21) + 0x1(20) = 0010 10102

b) −6310 = 1x32(25) + 1x16(24) + 1x8(23) + 1x4(22) + 1x2(21) + 1x1(20) = 1011 11112

c) 12410 = 1x64(26) + 1x32(25) + 1x16(24) + 1x8(23) + 1x4(22) + 0x2(21) + 0x1(20) = 0111 11002

d) −12810 = overflow

e) 13310 = overflow

Exercise 1.32 Convert the following decimal numbers to 8-bit sign/magnitude numbers or indicate that the decimal number would overflow the range

a) 2410

b) −5910

c) 12810

d) −15010

e) 12710

Solution:

a) 2410 = 0001 10002

b) −5910 = 1011 10112

c) 12810 = overflow

d) −15010 = overflow

e) 12710 = 0111 11112

Exercise 1.33 Convert the following 4-bit two's complement numbers to 8-bit two's complement numbers

a) 01012

b) 10102

Solution:

a) 01012 = 0000 01012

b) 10102 = 1111 10102

Exercise 1.34 Convert the following 4-bit two's complement numbers to 8-bit two's complement numbers

a) 01112

b) 10012

Solution:

a) 01112 = 0000 01112

b) 10012 = 1111 10012

Exercise 1.35 Repeat exercise 1.33 if the numbers are unsigned rather than two's complement

a) 01012

b) 10102

Solution:

a) 01012 = 0000 01012

b) 10102 = 0000 10102

Exercise 1.36 Repeat exercise 1.34 if the numbers are unsigned rather than two's complement

a) 01112

b) 10012

Solution:

a) 01112 = 0000 01112

b) 10012 = 0000 10012

Exercise 1.37 Base 8 is referred to as octal. Convert each of the numbers from exercise 1.25 to octal

a) 4210

b) 6310

c) 22910

d) 84510

Solution:

a) 4210 = 5x8(81) + 2x1(80) = 528

b) 6310 = 7x8(81) + 7x1(80) = 778

c) 22910 = 3x64(82) + 4x8(81) + 5x1(80) = 3458

d) 84510 = 1x512(83) + 5x64(82) + 1x8(81) + 5x1(80) = 15158

Exercise 1.38 Base 8 is referred to as octal. Convert each of the numbers from exercise 1.26 to octal

a) 1410

b) 5210

c) 33910

d) 71110

Solution:

a) 0o16

b) 0o64

c) 0o523

d) 0o1307

Exercise 1.39 Convert each of the following octal numbers to binary, hexadecimal, and decimal

a) 428

b) 638

c) 2558

d) 30478

Solution:

Convert Binary to Octal

Break a binary number into groups of 3 digits and convert each group separately. After that, just concatenate all the resulting octal digits.

a) 428 = 100 0102 = 0010 00102 = 2216 = 2x16 + 2 = 3410

b) 638 = 110 0112 = 0011 00112 = 3316 = 3x16 + 3 = 5110

c) 2558 = 010 101 1012 = 1010 11012 = AD16 = 10x16 + 13 = 17310

d) 30478 = 011 000 100 1112 = 0110 0010 01112 = 62716 = 6x256 + 2x16 + 7 = 157510

Exercise 1.40 Convert each of the following octal numbers to binary, hexadecimal, and decimal

a) 238

b) 458

c) 3718

d) 25608

Solution:

a) 0b10011; 0x13; 19

b) 0b100101; 0x25; 37

c) 0b11111001; 0xF9; 249

d) 0b10101110000; 0x570; 1392

Exercise 1.41 How many 5-bit two's complement numbers are greater than 0? How many are less than 0? How would your answer differ for sign/magnitude numbers?

Solution:

a) 15 greater than 0

b) 16 less than 0

c) 15 greater and 15 less for sign/magnitude

Exercise 1.42 How many 7-bit two's complement numbers are greater than 0? How many are less than 0? How would your answers differ for sign/magnitude numbers?

Solution:

a) (26-1) are greater than 0 = 63

b) 26 are less than 0 = 64

c) For sign/magnitude numbers, (26-1)=63 are still greater than 0, but (26-1)=63 are less than 0

Exercise 1.43 How many bytes are in a 32-bit word? How many nibbles are in the word?

Solution:

a) 4

b) 8

Exercise 1.44 How many bytes are in a 64-bit word?

Solution:

8

Exercise 1.45 A particular DSL modem operates at 768 kbit/sec. How many bytes can it receive in 1 minute?

Solution:

5760000

Exercise 1.46 USB 3.0 can send data at 5Gbits/sec. How many bytes can it send in 1 minute?

Solution:

(5×109 bits/second)(60 seconds/minute)(1 byte/8 bits) = 3.75×1010 bytes

Exercise 1.47 Hard disk manufacturers use the term "megabyte" to mean 106 bytes and "gigabyte" to mean 109 bytes. How many real GBs of music you can store on a 50GB hard disk?

Solution:

50x109/230=50 000 000 000 / 1 073 741 824 = 46.566 GBytes

tip

210 = 1024 ≈ 103 bytes (1 KBytes)

220 = 1 048 578 ≈ 106 bytes (1 MBytes)

230 = 1 073 741 824 ≈ 109 bytes (1 GBytes)

Exercise 1.48 Estimate the value of 231

Solution:

231=230x21
230 ≈ 1x109 ≈ 1 000 000 000
So 231 ≈ 2 000 000 000

Exercise 1.49 A memory on the Pentium II microprocessor is organized as a rectangular array of bits with 28 rows and 29 columns. Estimate how many bits it has without using a calculator?

Solution:

28 x 29 = 217 = 210 + 27 = 1 Kbits x 128 = 128 Kbits

Exercise 1.50 Draw a number line analogous to Figure 1.11 (see below) for 3-bit unsigned, two's complement, and sign/magnitude numbers

Solution:

-4-3-2-101234567
un000001010011100101110111
two100101110111000001010011
S/M111110101000 100001010011

Exercise 1.51 Draw a number line analogous to Figure 1.11 for 2-bit unsigned, two's complement, and sign/magnitude numbers

Solution:

-2-10123
unsigned00011011
two's10110001
Sign/M1100 1001

Exercise 1.52 Perform the following additions of unsigned binary numbers. Indicate whether or not the sum overflows a 4-bit result

a) 10012 + 01002

b) 11012 + 10112

Solution:

a) 1101

  1001
+ 0100
====
1101

b) 11110 (overflow)

  1101
+ 1011
====
1 1000 <- overflow
Unsigned Numbers

When the msb (most significant bit) is carried out, it's an overflow. For unsigned numbers.

Exercise 1.53 Perform the following additions of unsigned binary numbers. Indicate whether or not the sum overflows an 8-bit result

a) 100110012 + 010001002

b) 110100102 + 101101102

Solution:

a) 11011101

  10011001
+ 01000100
========
11011101

b) 110001000 (overflow)

  11010010
+ 10110110
========
1 10001000 <- overflow

Exercise 1.54 Repeat exercise 1.52, assuming that the binary numbers are in two's complement form

a) 10012 + 01002

b) 11012 + 10112

Solution:

a) 1101 (no overflow)

  1001
+ 0100
====
1101 (-8+4+1)=-3
Two's complement numbers

Overflow never occurs when adding two numbers with different signs

b) 1000 (no overflow)

  1101 = -3
+ 1011 = -5
====
1 1000 <- carry discarded
1000 -> result: -8
Two's Complement Numbers

When adding numbers in the two's complement form, the carry out from msb is discarding. See two's complement overflow

danger

Unlike unsigned numbers, a carry out of the most significant column does not indicate overflow

tip

Instead, overflow occurs if the two numbers being added have the same sign bit and the result has the opposite sign bit.

Exercise 1.55 Repeat exercise 1.53, assuming that the binary numbers are in two's complement form

a) 100110012 + 010001002

b) 110100102 + 101101102

Solution:

a) 11011101

  10011001
+ 01000100
========
11011101

b) 10001000

  11010010
+ 10110110
========
1 10001000 <- no overflow
10001000 -> result

Exercise 1.56 Convert the following decimal numbers to 6-bit two's complement binary numbers and add them. Indicate whether or not the sum overflows a 6-bit result

a) 1610+ 910

b) 2710 + 3110

c) −410 + 1910

d) 310 + −3210

e) −1610 + −910

f) −2710 + −3110

Solution:

a) 010000 + 001001 = 011001

   010000
+ 001001
======
011001 = 25

b) 011011 + 011111 = 111010 (overflow)

   011011 = 16+8+2+1=27
+ 011111 = 16+8+4+2+1=31
======
111010 <- sign bit changed (overflow)
result: -32+16+8+2=-6

c) 111100 + 010011 = 001111

   111100
+ 010011
======
1 001111 -> discard carry
001111 = 15

d) 000011 + 100000 = 100011

   000011
+ 100000
======
100011 = -32+2+1=-29

e) 110000 + 110111 = 100111

   110000 = -32+16=-16
+ 110111 = -32+16+4+2+1=-9
======
1 100111 -> discard carry
100111 = -32+4+2+1=-25

f) 100101 + 100001 = 000110 (overflow)

   100101 = -32+4+1=-27
+ 100001 = -32+1=-31
======
1 000110 -> discard carry
000110 -> changed msb
overflow!

Exercise 1.57 Repeat exercise 1.56 for the following numbers

a) 710 + 1310

b) 1710 + 2510

c) −2610 + 810

d) 3110 + −1410

e) −1910 + −2210

f) −210 + −2910

Solution:

a) 000111 + 001101 = 010100

000111 7
001101 13
======
010100

b) 010001 + 011001 = 101010, overflow

010001 17
011001 25
======
101010 -> overflow

c) 100110 + 001000 = 101110

100110 -26
001000 8
======
101110

d) 011111 + 110010 = 010001

 011111 31
110010 -14
======
1010001
010001

e) 101101 + 101010 = 010111, overflow

 101101 -19
101010 -22
======
1010111
010111 -> overflow

f) 111110 + 100011 = 100001

 111110 -2
100011 -29
======
1100001
100001 = -31

Exercise 1.58 Perform the following additions of unsigned hexadecimal numbers. Indicate whether or not the sum overflows an 8-bit (two hex digit) result

a) 716 + 916

b) 1316 + 2816

c) AB16 + 3E16

d) 8F16 + AD16

Solution:

a) 7 + 9 = 1016

 0111 
1001
====
10000

b) 13 + 28 = 3B

0001 0011
0010 1000
=========
0011 1011

c) AB + 3E = E9

1010 1011
0011 1110
=========
1110 1001

d) 8F + AD = 13С (overflow)

 1000 1111
1010 1101
=========
10011 1100 -> overflow

Exercise 1.59 Perform the following additions of unsigned hexadecimal numbers. Indicate whether or not the sum overflows an 8-bit (two hex digit) result

(a) 2216 + 816

(b) 7316 + 2C16

(c) 7F16 + 7F16

(d) C216 + A416

Solution:

a) 22 + 8 = 0x2A

0010 0010
0000 1000
=========
0010 1010

b) 73 + 2C = 0x9F

0111 0011
0010 1100
=========
1001 1111

c) 7F + 7F = 0xFE

0111 1111
0111 1111
=========
1111 1110

d) C2 + A4 = 0x166, overflow

 1100 0010
1010 0100
=========
10110 0110

Exercise 1.60 Convert the following decimal numbers to 5-bit two's complement binary numbers and subtract them. Indicate whether or not the difference overflows a 5-bit result

a) 910 − 710

b) 1210 − 1510

c) −610 − 1110

d) 410 − −810

Solution:

a) 9 - 7 = 01001 - 00111 = 00010

   01001 9
+ 11001 -7
=====
1 00010 <- carry discarded

b) 12 -15 = 01100 - 01111 = 11101

   01100 12    01100 12
- 01111 15 + 10001 -15
===== =====
11101 = 11101

c) −6 − 11 = 11010 - 01011 = 01111 (overflow)

  11010 -6     11010  -6
+ 10101 -11 - 01011 11
===== =====
1 01111 15 10111 -9

both error !! overflow

d) 4 − −8 = 00100 - 11000 = 01100

  00100 4   00100 4
+ 01000 8 10111
===== + 1
01100 - 11000 -8
=====
1 01100 12 <- carry discard

All Exercises