ProgrammingVery hardGATE CS · Campus placements
What is the total number of 1 bits in the binary forms of 1, 2, ..., 16 added together?
- A. 32
- B. 33
- C. 40
- D. 64
Correct answer: B. 33
Over 0..15 each of the 4 bit positions is set in exactly half the numbers, 4 x 8 = 32 bits, and 16 adds one more for 33. 32 stops at 15, 40 assumes 5 bit positions are each half set, and 64 counts all bits stored rather than set bits.
More C Programming questions
- uint16t s = 0; for (int i = 1; i <= 1000; i++) s += i; What is s at the end?
- #define CAT(a,b) a##b. After int CAT(num, 2) = 7; what does printf("%d", num2 2) print?
- int a = 1 ? 2 : 3 ? 4 : 5; What is a?
- char p = "xyz"; char a[] = "xyz"; a[0] = 'Q'; printf("%s", a); What is printed?
- char s[4] = "abc"; What is sizeof s?
- Ackermann-style recursion: A(0,n) = n + 1 and A(m,0) = A(m-1,1), with A(m,n) = A(m-1, A(m,n-1)). What is A(1,5)?