Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CS5002 Discrete Structures

Fall 2023

Homework # 1

Problem 1 [25 pts]: Number representations

i. convert 19010  to binary and hexadecimal?

ii. convert 01110111102  to decimal and hexadecimal.

iii. convert  FB0916   to  16-bit  2,s-complement.    Now,  treating  the  binary  as  a  16-bit  two,s-

complement number, ind the corresponding (negative) number in decimal

iv. convert 1102111113  to base-9.

v. The ancient Mayan civilization used a base-20 number system, although for calendaring ap- plications, they instead used base-18.  Their numbers were represented as dots and dashes. suppose instead we represent the Mayan digits as 0..9ABcDEFGHIJ (or 0..9ABcDEFGH for base 18). convert 181418  to base-20.

Problem 2 [30 pts]: Ip Addresses

your home,s address expresses where your house is in a network of roads.  similarly, an IP address expresses where a computer is in a network of computers. IP addresses are 32-bit binary numbers, commonly expressed in the dotted-decimal format in which the 32 bits are grouped into four bytes (each byte has 8 bits).   so the familiar dotted decimal notation  129.10.116.200 is equivalent to (10000001.00001010.01110100.11001000)2  because 129 = (10000001)2 , 10 = (00001010)2  and so on.

Notation

value

conversion from dot-decimal

Dotted decimal

192.0.2.235

Note: 192.0.2.235  19202235

Hexadecimal

0xc00002EB

The 32-bit number is expressed in hex

Decimal

3221226219

The 32-bit number is expressed in decimal.

octal

(030000001353)8

The 32-bit number is expressed in octal.

Binary

(11000000000000000000001011101011)2

The 32-bit number is expressed in binary

Table modiied from wikipedia on IPv4.   For  completeness, we include  octal though it is not commonly used. Binary is included so that you can see what a big mess it looks like, those larger bases shorten representations nicely.

i .  convert the IP address 159.95.213.32 from dotted decimal format to the hexadecimal and the decimal formats.

ii .  convert the IP address BAc1A39F from hexadecimal format to the dotted decimal and decimal formats.

iii .  convert the IP address 768744140 from decimal format to the hexadecimal and dotted decimal formats.

Problem 3 [30pts] 2,s complement & overlow

i. Give the decimal value which is represented by each of the following 8-bit two,s complement numbers: (11111110)2(01111111)2

ii. Give the 8-bit two,s complement representations of the following decimal values:  5o, 85, -69, -98.

iii. compute the following operations as a computer would, directly from the 8-bit two,s com- plement representations:  -69 + 5o,  -69 - 98, and 85 + 5o.  check your work by converting

values back to decimal form. Indicate whether the operation results in an overlow. Note:  use the two,s complement representations from part i above.

Problem 4 [15 pts:  (5, 5, 5)]:  More on number representation

i. what range of numbers can be represented in 11-bit two,s complement?

ii. what are the minimum number of bits necessary to represent 2o23 in two,s complement?

iii. what are the minimum number of bits necessary to represent -128 in two,s complement?

iv.  (Bonus [2pts]) How many ”magic card trick”cards you need to let a person choose a number between 1 and a million?