Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

UGC-NET | UGC NET CS 2018 Dec – II | Question 70

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

What does the following java function perform ? (Assume int occupies four bytes of storage)

Public static int f(int a) {
  //Pre-conditions : a>0 and no overflow/underflow occurs
  int b = 0;
  for (int i = 0; i < 32; i++) {
    b = b << 1;
    b = b | (a & 1);
    a = a >>> 1; // This is a logical shift
  }
  Return b;
}

(A) Return the int that represents the number of 0’s in the binary representation of integer a.
(B) Return the int that represents the number of 1’s in the binary representation of integer a.
(C) Return the int that has the reversed binary representation of integer a.
(D) Return the int that has the binary representation of integer a.


Answer: (C)

Explanation:

Quiz of this Question
Please comment below if you find anything wrong in the above post

My Personal Notes arrow_drop_up
Last Updated : 16 Sep, 2020
Like Article
Save Article
Similar Reads