Recitation2: CS 3843 Computer Organization Second week Instructor: Dr. Vijayalakshmi Saravanan TA: Tianyi Liu liuty10@gmail.ocm
Since 83 is positive & smaller than 127, Recitation2: 12 problems Problem1: 1. Using an 8-bit word, find the binary representation of 83 in 1. two's complement 2. ones' complement 3. sign-magnitude 4. as an unsigned 8-bit integer 83 = 5*16+3 = 0x53 = (0101 0011)b Since 83 is positive & smaller than 127, All the answers will be (0101 0011)b
-83 = -(5*16+3)=>1 101 0011 =>1 010 1100 =>1 010 1101 Recitation2: 12 problems Problem2: Using an 8-bit word, find the binary representation of -83 in 1. two's complement 2. ones' complement 3. sign-magnitude -83 = -(5*16+3)=>1 101 0011 Sign-magnitude =>1 010 1100 Ones’ complement =>1 010 1101 Two’s complement
Recitation2: 12 problems Problem3: Using a 16-bit word, find the binary representation of -83 in 1. two's complement 2. ones' complement 3. sign-magnitude -83 = -(5*16+3)=>1 000 0000 0101 0011 Sign-magnitude =>1 111 1111 1010 1100 Ones’ complement =>1 111 1111 1010 1101 Two’s complement
Recitation2: 12 problems Problem4: Convert each of the 10 values in problems 1-3 to two or four hexadecimal digits. Problem 1: [0101 0011] = 0x53 Problem 2: [1010 1101] = 0xad, [1010 1100] = 0xac, [1101 0011] = 0xd3 Problem 3: [1111 1111 1010 1101] = 0xffad, [1111 1111 10101 100] = 0xffac, [1000 0000 0101 0011] = 0x8053
Recitation2: 12 problems First, largest signed value must be positive Problem5: For w=7, what are the largest and smallest signed values? Problem6: For w=7, what are the largest and smallest unsigned values? First, largest signed value must be positive Second, the rest must be large enough First, largest unsigned value must be large enough smallest is 0. Sign-magnitude 1 1 1 1 1 1 Largest: 1 1 1 1 1 1 1 Ones’ complement 1 1 1 1 1 1 Smallest: Two’s complement 1 1 1 1 1 1 =3*16+15=63 Third, -0 stands for the smallest value, that is -64
Recitation2: 12 problems Problem7: 7*16+3=115 Assume w = 7, and convert -13 to unsigned. This means: represent -13 in 7-bit two's complement and then interpret the bit pattern as an unsigned integer. Express the result in decimal. First, what is -13 looks like in memory? Sign-magnitude 1 1 1 1 Ones’ complement 1 1 1 1 Two’s complement Treat it as an unsigned number 1 1 1 1 1 7*16+3=115
Recitation2: 12 problems Problem8:Assume w = 7, and convert unsigned 53 to signed. Problem9: Assume w = 7, and convert unsigned 103 to signed. 53=16*3+5 103=16*6+7 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Treat it as two’s complement Then, what’s it in decimal? 1 1 1 1 1 1 1 1 No-Change - 25
1. What is 357 looks like in memory? I mean two’s complement. Recitation2: 12 problems 0 01 0110 0101 Problem10: Assume that a short is represented by 7 bits and an int is represented by 11 bits. What is the output generated by the following code segment: int x = 357; int y = -357; short sx = (short)x; short sy = (short)y; printf("%d %d %d %d\n",x, y, (int)sx, (int)sy); printf("%x %x %x %x\n",x, y, (int)sx, (int)sy); printf("%u %u %u %u\n",x, y, (int)sx, (int)sy); 2. How about -357? 1 10 1001 1011 3. What is short sx ? 110 0101 4. What is short sy ? 001 1011 5. (int)sx, int(sy) means extend sx and sy to 11 bits. So, as signed value, we should extend the signal bit. (int)sy=000 0001 1011 (int)sx=111 1110 0101
Recitation2: 12 problems x=0 01 0110 0101 y=1 10 1001 1011 1. What we have now? Recitation2: 12 problems x=0 01 0110 0101 Problem10: Assume that a short is represented by 7 bits and an int is represented by 11 bits. What is the output generated by the following code segment: int x = 357; int y = -357; short sx = (short)x; short sy = (short)y; printf("%d %d %d %d\n",x, y, (int)sx, (int)sy); printf("%x %x %x %x\n",x, y, (int)sx, (int)sy); printf("%u %u %u %u\n",x, y, (int)sx, (int)sy); y=1 10 1001 1011 (int)sx =1 11 1110 0101 (int)sy =0 00 0001 1011 2. %d: output the value in decimal x=357, y=-357, (int)sx=(1 00 0001 1011)s-m=-27 3. %x: output the value in hexadecimal x=0x165, y=0x69b, (int)sx=0x7e5, (int)sy=0x01b 4. %u: output the value in unsigned int format x=357, y=1691, (int)sx=2021, (int)sy=27
Recitation2: 12 problems Problem11: Perform the following addition in binary without converting to another base. You must show the carries.
Recitation2: 12 problems Problem12: Perform the following addition in hexadecimal without converting to another base. You must show the carries.