a.)
b.) (238 - 1) * 2 = 549,755,813,886 c.) 4638 1 0 0 1 0 0 0 0 1 1 1 1 0 - 4096 4096 2048 1024 512 256 128 64 32 16 8 4 2 1 ------ 542 - 512 ----- 30 - 16 ---- 14 - 8 --- 6 - 4 --- 2 - 2 --- 0
a.) 00000111 = 7 11111000 (flip) +1 (add 1) -------- 11111001 = -7 in 8-bit 2's complement b.) 10000000 = 128 01111111 (flip) +1 (add 1) -------- 10000000 = -128 in 8-bit 2's complement c.) 01010111 = +87 (no need to flip/add 1 since it is positive) d.) 00000000 01010111 = 87 (in 16 bits) 11111111 10101000 (flip) +1 (add 1) ----------------- 11111111 10101001 = -87 in 16-bit 2's complement e.) -1 in 36 bits is 111111111111111111111111111111111111 (36 1's) f.) -4 in 80 bits is 1111......11100 (78 1's)
a.) 10001010 is negative because 1st bit is 1 10001010 01110101 (flip) +1 (add 1) -------- 01110110 = 118 so the original number was -118 b.) 1111000011110000 is negative because 1st bit is 1 1111000011110000 0000111100001111 (flip) +1 (add 1) ---------------- 0000111100010000 = 3856 so the original number as -3856 c.) 1111111111111000 is negative because 1st bit is 1 1111111111111000 0000000000000111 (flip) +1 (add 1) ---------------- 0000000000001000 = 8 so the original number as -8 d.) 0100000000000001 is positive because 1st bit is 0 ^ ^ | | 16384 1 = +16385
a.) 68 = 01000100 + -87 = + 10101001 (2's complement, 8 bits) ------ ---------- -19 11101101 ---> 00010010 + 1 = 00010011 = -19 b.) -101 = 10011011 (details of conversion to 2's comp not shown) + -36 = + 11011100 ------ ---------- -137 101110111 (oops, overflow, can't fit in 8 bits) 01110111 = +119, which is not -137 So when we get a carry out like (b) we have overflow and the answer can't fit in the allotted number of bits.
bit pattern unsigned 2's complement -------------------------------------------------------- 1000 8 -8 1001 9 -7 1010 10 -6 1011 11 -5 1100 12 -4 1101 13 -3 1110 14 -2 1111 15 -1 0000 0 0 0001 1 1 0010 2 2 0011 3 3 0100 4 4 0101 5 5 0110 6 6 0111 7 7
a.) 10010111 C=___1__ N=___0__ + 10001001 Z=___0__ V=___1__ ----------- 1 00100000 b.) 01010111 C=___1__ N=___0__ + 11101001 Z=___0__ V=___0__ ----------- 1 01000000 c.) 00000100 C=___1__ N=___0__ + 11111100 Z=___1__ V=___0__ ----------- 1 00000000 d.) 00111011 C=___0__ N=___1__ + 01011010 Z=___0__ V=___1__ ----------- 0 10010101
a.) 1 0 1 1 0 1 1 1 logical shift left 1 bit (SHLL) / / / / / / / / / lost 0 1 1 0 1 1 1 0 (insert 0 from outer space) b.) 1 0 1 1 0 1 1 1 logical shift right 1 bit (SHLR) \ \ \ \ \ \ \ \ \ 0 1 0 1 1 0 1 1 lost (insert 0 from outer space on the left) c.) 1 0 1 1 0 1 1 1 circular shift right 1 bit (SHCR) \ \ \ \ \ \ \ \ 1 1 0 1 1 0 1 1 \ (copy the rightmost 1 around to the left) ^ | | | +---------------+ d.) 1 0 1 1 0 1 1 1 arithmetic shift right 1 bit (SHAR) |\ \ \ \ \ \ \ \ 1 1 0 1 1 0 1 1 lost (copy the sign bit into two bits) e.) 1 0 1 1 0 1 1 1 arithmetic shift left 1 bit (SHAL) |/ / / / / / / / 1 1 1 0 1 1 1 0 (insert 0 from outer space) X problem here, 1 and 0 clash, hence overflow occurs
a.) 10010001111 & 01100011101 (and) ------------- 00000001101 b.) 10010001111 | 01100011101 (or) ------------- 11110011111 c.) ^ 10010001111 (not) ------------- 01101110000 (same as "flip" operation)
a.) determine if the character in ch is printable if (ch >= 32 && ch <= 126) ... b.) determine if the character in ch is a printable punctuation symbol if (ch >= 32 && ch <= 47 || ch >= 58 && ch <= 64 || ch >= 91 && ch <= 96 || ch >= 123 && ch <= 126) ... c.) convert an uppercase letter to lowercase (don't need to check to make sure it is uppercase first) ch += 32; 'A' = 65, 'a' = 97 97-65 = 32