edited by
1,239 views
0 votes
0 votes

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 oveflow/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;
}
  1. Returns the int that has the binary representation of integer a
  2. Return the int that has reversed binary representation of integer a
  3. Return the int that represents the number of $1$’s in the binary representation of integer a
  4. Return the int that represents the number of $0$’s in the binary representation of integer a
edited by

1 Answer

Related questions

1 votes
1 votes
0 answers
3
0 votes
0 votes
2 answers
4
Arjun asked Jan 2, 2019
4,377 views
Consider the graph shown below:Use Kruskal’s algorithm to find the minimum spanning tree of the graph. The weight of this minimum spanning tree is$17$$14$$16$$13$