Consider the following function ) : f n unsigned int (unsigned int )( b = 0
unsigned int ;
while (n) {
b+ = n&1
;
n ≫>= 1
;
}
return b;}
```
f (The function ) returns the int that represents _P_ the in the binary representation of positive n P
integer , where is
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: D. number of 1's
Explanation
b += n & 1; n >>= 1 adds each low bit and shifts: it counts the 1 bits.
More Programming Languages and Computer Graphics questions
- Consider a raster system with resolution 640 by 480 . What size is frame buffer (in bytes) for this system to store 12 bits per pixel?
- Consider the following statements regarding 2D transforms in computer graphics: 1 0 [ ] 2 × 2 S1 : is a matrix that reflects 0 −1 2D X (mir…
- In the context of 3D computer graphics, which of the following statements is/are true? P : Orthographic transformations keep parallel lines…
- Using the phong reflectance model, the strength of the specular highlight is determined by the angle between
- If the frame buffer has 10-bits per pixel and 8- bits are allocated for each of the R, G, and B components, then what would be the size of…
- Which homogeneous 2D matrix transforms the figure (a) on the left side to the figure (b) on the right ?