ProgrammingModerateTCS NQT · Infosys
How many integers i with 1 <= i <= 100 have bit 3 (value 8) set in their binary form?
- A. 50
- B. 36
- C. 52
- D. 48
Correct answer: D. 48
Bit 3 repeats in blocks of 16, with 8 set in every second block. Numbers 1 to 96 contain six full blocks, giving 48, and 97 to 100 add none.
More C Programming questions
- uint32t x = 0x12345678u; the 32-bit left rotation by 8 bits, written as (x << 8) | (x >> 24), gives what value?
- What is the Hamming distance between a = 0b1011 and b = 0b0110, that is the number of bit positions where they differ?
- A uint32t x = 37 is rounded up to a power of two by this code: x--; x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; x++…
- int a = -7, m = 5; What is ((a % m) + m) % m, the non-negative residue of a modulo m?
- unsigned char c = 200; int r = (c c) >> 8; What is r?
- unsigned char c = 0xF0; printf("%d", ~c); prints what?