written homework 01 - northeastern university · written homework 01 assigned: mon 12 sep 2016 due:...

7
CS1800 Discrete Structures Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague Fall 2016 September 7, 2016 Written Homework 01 Assigned: Mon 12 Sep 2016 Due: Wed 21 Sep 2016 Instructions: The assignment has to be uploaded to Blackboard by the due date. NO assignment will be accepted after 11:59pm on that day. We expect that you will study with friends and often work out problem solutions together, but you must write up your own solutions, in your own words. Cheating will not be tolerated. Professors, TAs, and peer tutors will be available to answer questions but will not do your homework for you. One of our course goals is to teach you how to think on your own. You may turn in work to Blackboard that is either handwritten and scanned, written in a word processor such as Word, or typeset in LaTeX. In the case of handwritten work, we may deduct points if the scan is upside down or the work is illegible. To get full credit , show INTERMEDIATE steps leading to your answers, throughout. Problem 1 [30 pts, (5 pts each)]: Base conversions and IP address formats In each of the parts below, perform the calculations by hand and show your work. i. Convert the decimal integer 2020 to binary. Solution: 2020 = 1024 + 512 + 256 + 128 + 64 + 32 + 4 = 2 10 +2 9 +2 8 +2 7 +2 6 +2 5 +2 2 = (11111100100) 2 ii. Convert the decimal integer 2020 to octal. You may start with the binary string you created above. Solution: 11111100100 = 011 111 100 100 = (3744) 8 iii. Convert the decimal integer 2020 to hexadecimal. Again, you may start with the binary string you created in part (i). Solution: 11111100100 = 0111 1110 0100 = (7E4) 16 1

Upload: lynhan

Post on 14-May-2018

228 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Written Homework 01 - Northeastern University · Written Homework 01 Assigned: Mon 12 Sep 2016 Due: Wed 21 Sep 2016 Instructions: The assignment has to be uploaded to Blackboard by

CS1800 Discrete Structures Profs. Aslam, Gold, Ossowski, Pavlu, & SpragueFall 2016 September 7, 2016

Written Homework 01

Assigned: Mon 12 Sep 2016Due: Wed 21 Sep 2016

Instructions:

• The assignment has to be uploaded to Blackboard by the due date. NO assignment will be acceptedafter 11:59pm on that day.

• We expect that you will study with friends and often work out problem solutions together, but youmust write up your own solutions, in your own words. Cheating will not be tolerated. Professors,TAs, and peer tutors will be available to answer questions but will not do your homework for you.One of our course goals is to teach you how to think on your own.

• You may turn in work to Blackboard that is either handwritten and scanned, written in a wordprocessor such as Word, or typeset in LaTeX. In the case of handwritten work, we may deduct pointsif the scan is upside down or the work is illegible.

• To get full credit , show INTERMEDIATE steps leading to your answers, throughout.

Problem 1 [30 pts, (5 pts each)]: Base conversions and IP address formats

In each of the parts below, perform the calculations by hand and show your work.

i. Convert the decimal integer 2020 to binary.

Solution:

2020 = 1024 + 512 + 256 + 128 + 64 + 32 + 4= 210 + 29 + 28 + 27 + 26 + 25 + 22

= (11111100100)2

ii. Convert the decimal integer 2020 to octal. You may start with the binary string you createdabove.

Solution:

11111100100 = 011 111 100 100 = (3744)8

iii. Convert the decimal integer 2020 to hexadecimal. Again, you may start with the binarystring you created in part (i).

Solution:

11111100100 = 0111 1110 0100 = (7E4)16

1

Page 2: Written Homework 01 - Northeastern University · Written Homework 01 Assigned: Mon 12 Sep 2016 Due: Wed 21 Sep 2016 Instructions: The assignment has to be uploaded to Blackboard by

IP addresses are 32-bit binary numbers, most commonly expressed in the dotted-decimal formatin which the 32 bits are grouped into four bytes of 8 bits each, separated by the dot symbol, andeach byte is written out in decimal form. Thus, the following IP address, written in binary,

10000001000010100111010011001000

is written as follows in the dotted decimal notation:

129.10.116.200

The first eight bits 10000001 form the number 129 in decimal notation, the next eight bits 00001010form the number 10, the next eight bits 01110100 form the number 116, and finally the last eightbits 11001000 form the number 200.IP addresses can also be represented in other formats, including hexadecimal and decimal. In fact,most browsers will accept IP addresses in these representations as well. These formats are usedsometimes for purposes of obfuscation and identity-hiding.

Notation Value Conversion from dot-decimal

Dotted decimal 192.0.2.235 N/A

Hexadecimal 0xC00002EB The 32-bit number is expressed as the concatenation of theoctets from the dotted hexadecimal.(We are omitting the’0x” here.)

Decimal 3221226219 The 32-bit number is expressed in decimal.

Octal 030000001353 The 32-bit number is expressed in octal.This table is from Wikipedia on IPv4

iv. Convert the IP address 163.70.255.48 from dotted decimal format to the hexadecimal and thedecimal formats.

Solution:

(163)10 = 10100011 = 1010 0011 = (A3)16(70)10 = 01000110 = 0100 0110 = (46)16(255)10 = 11010011 = 1111 1111 = (FF )16(48)10 = 00110000 = 0011 0000 = (30)16

The IP address 163.70.255.48 in hexadecimal format is A346FF30.

The binary representation of the IP address 163.70.255.48 is:10100011010001101111111100110000

One can find the value in decimal format by converting either the hexadecimal representa-tion (A346FF30)16 or the binary representation (10100011010001101111111100110000)2 todecimal. For example:

(A346FF30)16 = 10× 167 + 3× 166 + 4× 165 + 6× 164 + 15× 163 + 15× 162 + 3× 16 + 0 =(2739339056)10.

The IP address 163.70.255.48 in decimal format is 2739339056.

2

Page 3: Written Homework 01 - Northeastern University · Written Homework 01 Assigned: Mon 12 Sep 2016 Due: Wed 21 Sep 2016 Instructions: The assignment has to be uploaded to Blackboard by

v. Convert the IP address E57C54AB from hexadecimal format to the dotted decimal and dec-imal formats.

Solution:

First byte: (E5)16 = 14× 16 + 5 = (229)10

Second byte: (7C)16 = 7× 16 + 12 = (124)10

Third byte: (54)16 = 5× 16 + 4 = (84)10

Fourth byte: (AB)16 = 10× 16 + 11 = (171)10

The IP address E57C54AB in dotted decimal format is 229.124.84.171.

(E57C54AB)16 = 14× 167 + 5× 166 + 7× 165 + 12× 164 + 5× 163 + 4× 162 + 10× 16 + 11 =(3581621423)10.

The IP address E57C54AB in decimal format is 3850130603.

vi. Convert the IP address 1234567890 from decimal format to the hexadecimal and dotteddecimal formats.

Solution:

(1234567890)10 = (01001001100101100000001011010010)2= (0100 1001 1001 0110 0000 0010 1101 0010)2= (499602D2)16

The IP address 1234567890 in hexadecimal format is 499602D2.

First byte: (01001001)2 = (73)10

Second byte: (10010110)2 = (150)10

Third byte: (00000010)2 = (2)10

Fourth byte: (11010010)2 = (210)10

The IP address 1234567890 in dotted decimal format is 73.150.2.210.

Problem 2 [24 pts (6 pts each)]: Negative numbers and two’s complement.

In each of the parts below, show your work.

i. Give the 8-bit two’s complement representations of the following integers: 42, 23, −42, −127.

Solution:

42 = 32 + 8 + 2 = 0010101023 = 16 + 4 + 2 + 1 = 00010111

3

Page 4: Written Homework 01 - Northeastern University · Written Homework 01 Assigned: Mon 12 Sep 2016 Due: Wed 21 Sep 2016 Instructions: The assignment has to be uploaded to Blackboard by

−42 =⇒ 42 = 32 + 8 + 2 = 00101010 =⇒ 11010110−127 =⇒ 127 = 64 + 32 + 16 + 8 + 4 + 2 + 1 = 01111111 =⇒ 10000001

ii. Give the integer (in standard base-10 notation) which is represented by each of the following8-bit two’s complement numbers: 10101000, 11111111, 10000001.

Solution:

10101000 =⇒ 01011000 = 88 =⇒ −88

11111111 =⇒ 00000001 = 1 =⇒ −1

10000001 =⇒ 01111111 = 127 =⇒ −127

iii. Compute the following using 8-bit two’s complement representations, as shown in class anddescribed in the text: 23 + −42, −42 + −42, and −42 + −127. Use only 8 bits, discardingextra carried bits. Then convert the result back to decimal and state whether the correctanswer was obtained.

Note: Use the two’s complement representations from part i above.

Solution:

0 0 0 1 0 1 1 1 = 23+ 1 1 0 1 0 1 1 0 = −42

1 1 1 0 1 1 0 1 = −19

The correct answer was obtained.

1 1 0 1 0 1 1 0 = −42+ 1 1 0 1 0 1 1 0 = −42

1 0 1 0 1 1 0 0 = −84

The correct answer was obtained.

1 1 0 1 0 1 1 0 = −42+ 1 0 0 0 0 0 0 1 = −127

0 1 0 1 0 1 1 1 = 87

Overflow causes an error here.

iv. What range of numbers can be represented in (a) 9-bit two’s complement? What are theminimum number of bits necessary to represent (b) 2020 and (c) −512 in two’s complement?

Solution:

(a) −256 to 255: 8 bits to represent the magnitude of the number and 1 bit to represent itssign, where 28 = 256. Since 0 only has one representation (000000000), we have one extrabit pattern – 100000000 – which we use for −256. In general, the range of an n-bit two’scomplement representation is −2n−1 to 2n−1 − 1, inclusive.

(b) 12 bits. Because 210 − 1 = 1023 < 2020 ≤ 2047 = 211 − 1, we need 11 bits for themagnitude, and then one bit for the sign.

4

Page 5: Written Homework 01 - Northeastern University · Written Homework 01 Assigned: Mon 12 Sep 2016 Due: Wed 21 Sep 2016 Instructions: The assignment has to be uploaded to Blackboard by

(c) 10 bits. For the same reasoning as (b), because −29 = −512 plus one bit for the sign.

Problem 3 [28pts (8,8,12)] Logical completeness.

Every truth table, Boolean formula, and circuit can be implemented using just AND, OR, andNOT gates; hence, the collection {AND,OR,NOT} is logically complete. But, we actually don’tneed all three to implement any circuit.

i. Fill in the following truth table:

X Y ¬(¬X AND ¬Y )

0 0 ?0 1 ?1 0 ?1 1 ?

Examine the truth table you’ve created. What does ¬(¬X AND ¬Y ) simplify to?

Solution:

X Y ¬(¬X AND ¬Y )

0 0 00 1 11 0 11 1 1

¬(¬X AND ¬Y ) is simply X OR Y.

ii. Fill in the following truth table:

X Y ¬(¬X OR ¬Y )

0 0 ?0 1 ?1 0 ?1 1 ?

Examine the truth table you’ve created. What does ¬(¬X OR ¬Y ) simplify to?

Solution:

X Y ¬(¬X OR ¬Y )

0 0 00 1 01 0 01 1 1

¬(¬X OR ¬Y ) is simply X AND Y.

5

Page 6: Written Homework 01 - Northeastern University · Written Homework 01 Assigned: Mon 12 Sep 2016 Due: Wed 21 Sep 2016 Instructions: The assignment has to be uploaded to Blackboard by

iii. (a) Draw a circuit that implements OR using only AND and NOT gates. (b) Draw a circuitthat implements AND using only OR and NOT gates. (c) Draw a circuit that implementsXOR (exclusive or) using only AND and NOT gates.

Solution: (a)

(b)

(c)

6

Page 7: Written Homework 01 - Northeastern University · Written Homework 01 Assigned: Mon 12 Sep 2016 Due: Wed 21 Sep 2016 Instructions: The assignment has to be uploaded to Blackboard by

Problem 4 [18pts (3 pts each)] Logical formulas.Write a logical formula that is true if and only if the described condition is true. For example,

if the description is “A, B, and C are all true, but D is not,” you would write A∧B ∧C ∧¬D. Use∧, ∨, and ¬ for AND, OR, and NOT.

i. At least one of A, B, or C is true.

Solution: A ∨B ∨ C

ii. A, B, and C, all have the same value (of true or false).

Solution: (A ∧B ∧ C) ∨ (¬A ∧ ¬B ∧ ¬C)

iii. At least two of A, B, and C are true.

Solution: (A ∧B) ∨ (A ∧ C) ∨ (B ∧ C)

iv. At least one member of each group must be true: group 1 contains A, B, and C, group 2contains D, E, and F, and group 3 contains A, F, and G. (Thus if A is true, it satisfies therequirement for both group 1 and group 3.)

Solution: (A ∨B ∨ C) ∧ (D ∨ E ∨ F ) ∧ (A ∨ F ∨G)

v. Exactly one of A, B, or C is true.

Solution: (A ∧ ¬B ∧ ¬C) ∨ (B ∧ ¬A ∧ ¬C) ∨ (C ∧ ¬A ∧ ¬B)

vi. At least one of A, B, or C is false. Do not use ∨ (OR).

Solution: ¬(A ∧B ∧ C)

7