### Solution for HW1 - CS255

• Question 1

 ``` (1) Divide repeatedly by 2: 4317 2 -------- 1 2158 2 -------- 0 1079 2 -------- 1 539 2 -------- 1 269 2 -------- 1 134 2 -------- 0 67 2 -------- 1 33 2 -------- 1 16 2 -------- 0 8 2 -------- 0 4 2 -------- 0 2 2 -------- 0 1 2 -------- 1 0 answer: 4317 is represented by 00010000 11011101 (2 bytes !!!) To get representation for -4317, subtract: 1 00000000 00000000 00010000 11011101 --------------------- 11101111 00100011 answer: -4317 is represented by 11101111 00100011 ```

 ``` (2) 5432 1098 7654 3210 0000 0010 0100 0101 represents the value: 29 + 26 + 22 + 20 = 512 + 64 + 4 + 1 = 581 1111 0001 0101 0111 represents a negative value, first convert to positive: 1 0000 0000 0000 0000 1111 0001 0101 0111 ------------------------- 0000 1110 1010 1001 5432 1098 7654 3210 0000 1110 1010 1001 represents the positive value: 211 + 210 + 29 + 27 + 25 + 23 + 20 = 2048 + 1024 + 512 + 128 + 32 + 8 + 1 = 3753 So 1111 0001 0101 0111 represents: -3753 ```

 ``` (3) Pattern 1: 0000 0010 0100 0101 Pattern 2: 1111 0001 0101 0111 + ------------------------- 1111 0011 1001 1100 1111 0011 1001 1100 represents a negative value, first convert to positive: 1 0000 0000 0000 0000 1111 0011 1001 1100 ------------------------- 0000 1100 0110 0100 5432 1098 7654 3210 0000 1100 0110 0100 represents the positive value: 211 + 210 + 26 + 25 + 22 = 2048 + 1024 + 64 + 32 + 4 = 3172 So 1111 0011 1001 1100 represents: -3172 (BTW: 581 + (-3753) = -3172 !!!) ```

 ``` (4) Pattern 2: 1111 0001 0101 0111 Pattern 1: 0000 0010 0100 0101 - ------------------------- 1110 1111 0001 0010 1110 1111 0001 0010 represents a negative value, first convert to positive: 1 0000 0000 0000 0000 1110 1111 0001 0010 ------------------------- 0001 0000 1110 1110 5432 1098 7654 3210 0001 0000 1110 1110 represents the positive value: 212 + 27 + 26 + 25 + 23 + 22+ 21 = 4096 + 128 + 64 + 32 + 8 + 4 + 2 = 4334 So 1110 1111 0001 0010 represents: -4334 (BTW: (-3753) - 581 = -4334 !!!) ```

• Question 2

 ``` (1) 10's complement repr. in 4 digits for value 3429 is: 3429 10's complement repr. in 4 digits for value -3429 is: 10000 - 3429 ------- 6571 answer: 6571 ```

 ``` (2) 8896 represents a negative value. Convert first: 10000 - 8896 ------- 1104 The absolute value is 1104 So 8896-1104 ```

 ``` (3) Add: 9765 represents: -235 9995 + represents: -5 --------- 9760 represents: -240 Yes, the addition results in the representation of the correct value ```

 ``` (4) Multiply: 9765 represents: -235 9995 x represents: -5 --------- 48825 878850 8788500 87885000 ------------- 97601175 Truncate to 4 digits: 1175 represents: +1175 Yes, multiply results in the representation of an correct value ```

• Question 3

 ``` (1) Multiply: (binary) 11110101 1101 x ----------------- 11110101 00000000 11110101 11110101 ------------------ 110001110001 ```

 ``` (2) Divide (binary): 10010 ---------- 1101 / 11110101 1101 ---- 100 000 --- 1001 0000 ---- 10010 1101 ----- 1011 0000 ---- 1011 ```

• Question 4

 ``` Use the multiplication for base-5 (from class): | 1 2 3 4 ----+------------------- 1 | 1 2 3 4 2 | 2 4 11 13 3 | 3 11 14 22 4 | 4 13 22 31 1432 2414 x ---------- 12333 14320 1233300 3414000 ------------ 10240003 ```

• Question 5

 ``` 1. Represent the value 4539 in octal number system: Get the factors of 8 by dividing the number repeated by 8 4539 8 --------- 3 567 8 --------- 7 70 8 --------- 6 8 8 --------- 0 1 8 --------- 1 0 Answer: 10673(8) ```

 ``` 2. Represent the value 4539 in hexadeciaml number system: Get the factors of 8 by dividing the number repeated by 16 4539 16 ------------ 11 283 16 ------------ 11 17 16 ------------ 1 1 16 ------------ 1 0 Answer: 11BB(16) ```

 ``` 3. Represent the value 4539 in nano number system: Get the factors of 9 by dividing the number repeated by 9 4539 9 ------------ 3 504 9 ------------ 0 56 9 ------------ 2 6 9 ------------ 6 0 Answer: 6203(9) ```

 ``` 3. Represent the value 4539 in base 13 number system: Get the factors of 13 by dividing the number repeated by 13 4539 13 ------------ 2 349 13 ------------ 11 26 13 ------------ 0 2 13 ------------ 2 0 Answer: 20B2(9) ```

• Question 6

 ``` (1) "Huh?" Use the ASCII code 'H' 'u' 'h' '?' 01001000 01110101 01101000 00111111 (2) 'x' '=' '5' '2' ';' 01111000 00111101 00110101 00110010 00111011 (3) Stores 2's complement representation of 52 in 8 bits: 00110100 (4) 'x' '=' '0' ';' 01111000 00111101 00110000 00111011 (5) Stores 2's complement repr of 0 in 32 bits: 00000000 00000000 00000000 00000000 (6) 1230578 = 001 010 011 000 101 111 or 001010011000101111 or 1010011000101111 (7) BAD4(16) = 1011 1010 1101 0100 or 1011101011010100 (8) 4.0 4(10) = 100(2) 0.0(10) = 0.0(2) So: 4.0(10) = 100.0(2) Normalize: 100.0(2) = 1.0(2) × 210(2) Mantissa = 1.0(2) Exponent = 10(2) Stored Mantissa = 0.0(2) Stored Exponent = 10000001(2) (01111111 represents 0) The representation is therefore: 0 10000001 000000000.............0 (9) 7.75 7(10) = 111(2) 0.75(10) = 0.11(2) So: 7.75(10) = 111.11(2) Normalize: 111.11(2) = 1.1111(2) × 210(2) Mantissa = 1.1111(2) Exponent = 10(2) Stored Mantissa = 0.1111(2) Stored Exponent = 10000001(2) (01111111 represents 0) The representation is therefore: 0 10000001 111100000.............0 (10) The representation given is: 11000001010001000000000000000000 Broken into the IEEE format: 1 10000010 10001000000000000000000 Signed = 1 ==> negative Stored Mantissa = 0.10001(2) Stored Exponent = 10000010(2) (01111111 represents 0) Actual mantissa = 1.10001(2) Value of exponent = 11(2) The binary floating point number is therefore: -1.10001(2) × 211(2) = -1100.01(2) 1100(2) = 12(10) 0.01(2) = 0.25(10) The value represented is equal to: -12.25(10) ```