Presentation is loading. Please wait.

Presentation is loading. Please wait.

Recitation2: CS 3843 Computer Organization Second week

Similar presentations


Presentation on theme: "Recitation2: CS 3843 Computer Organization Second week"— Presentation transcript:

1 Recitation2: CS 3843 Computer Organization Second week
Instructor: Dr. Vijayalakshmi Saravanan TA: Tianyi Liu

2 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 = ( )b Since 83 is positive & smaller than 127, All the answers will be ( )b

3 -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)=> Sign-magnitude => Ones’ complement => Two’s complement

4 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)=> Sign-magnitude => Ones’ complement => Two’s complement

5 Recitation2: 12 problems Problem4: Convert each of the 10 values in problems 1-3 to two or four hexadecimal digits. Problem 1: [ ] = 0x53 Problem 2: [ ] = 0xad, [ ] = 0xac, [ ] = 0xd3 Problem 3: [ ] = 0xffad, [ ] = 0xffac, [ ] = 0x8053

6 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

7 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

8 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

9 1. What is 357 looks like in memory? I mean two’s complement.
Recitation2: 12 problems 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? 3. What is short sx ? 4. What is short sy ? 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= (int)sx=

10 Recitation2: 12 problems x=0 01 0110 0101 y=1 10 1001 1011
1. What we have now? Recitation2: 12 problems x= 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= (int)sx = (int)sy = 2. %d: output the value in decimal x=357, y=-357, (int)sx=( )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

11 Recitation2: 12 problems Problem11: Perform the following addition in binary without converting to another base. You must show the carries.

12 Recitation2: 12 problems Problem12: Perform the following addition in hexadecimal without converting to another base. You must show the carries.


Download ppt "Recitation2: CS 3843 Computer Organization Second week"

Similar presentations


Ads by Google