1 / 8

Quiz 2

Quiz 2. Question 1. What is -10 10 in 5 bit 2’s complement notation? First determine what +10 2 is It’s 1010 (1 * 8 + 0 * 4 + 1 * 2 + 0 * 1 ) Pad it with zeroes to 5 bits: 01010 Then flip the bits 01010 flipped is 10101 And finally add 1 10101 + 1 = 10110

keelia
Download Presentation

Quiz 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Quiz 2

  2. Question 1 • What is -1010 in 5 bit 2’s complement notation? • First determine what +102is • It’s 1010 (1 * 8 + 0 * 4 + 1 * 2 + 0 * 1) • Pad it with zeroes to 5 bits: 01010 • Then flip the bits • 01010 flipped is 10101 • And finally add 1 • 10101 + 1 = 10110 • If you want to check your answer reverse the process and you should end up with 01010

  3. Informal Conversion Algorithm • Say you want to convert 70110 to binary • Find the largest power of 2 that 701 is divisible by • It’s 512 (1,2,4,8,16,32,64,128,256,512,1024,2048,...) • Write down 1 • Subtract 512 from 701 = 189 • Go through the lower powers of 2 one by one • If the power of 2 is less than the number repeat • Otherwise write down a 0 and move on

  4. Example • 701 – 512 = 189 • 1 • 256 > 189 • 10 • 189 – 128 = 61 • 101 • 64 > 61 • 1010 • 61 – 32 = 29 • 10101 • 29 – 16 = 13 • 101011 • 13 – 8 = 5 • 1010111 • 5 – 4 = 1 • 10101111 • 2 > 1 • 101011110 • 1 – 1 = 0 (so we are done) • 1010111101

  5. Question 2 • What do the printf statements shown below print? • int x = 7; • x--; • printf(“%d”,x); • 6 • printf(“%d”,20 / 3); • 6

  6. Question 3 • What does the printf statement shown below print? • if(3 > -7 && 12 < 15) • printf(“true”); • else • printf(“false”); • true

  7. Question 4 • Write a complete program that prompts the user to enter two numbers and that prints the remainder of the first divided by the second. • #include“stdio.h” • int main() • { • int dividend, divisor; • printf(“Please enter the dividend: ”); • scanf(“%d”, &dividend); • printf(“Please enter the dividend: ”); • scanf(“%d”, &divisor); • printf(“remainder = %d”, dividend % divisor); • return 0; • }

  8. Question 5 • Write a function to return 1 if its single integer parameter is even, and 0 otherwise • inteven(int x) • { • if(x % 2 == 0){ • return 1; • }else{ • return 0; • } • }

More Related