# UGCNET-DEC2018-II: 49

290 views

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
0

option B.

Note that <<< is logical shift Right ===> sign extension doesn't takes place

## Related questions

1 vote
1
1.1k views
​​​​​​In mathematical logic, which of the following are statements? There will be snow in January. What is the time now? Today is Sunday. You must study Discrete mathematics Choose the correct answer from the code given below: i and iii i and ii ii and iv iii and iv
​​A box contains six red balls and four green balls. Four balls are selected at random from the box. What is the probability that two of the selected balls will be red and two will be in green? $\frac{1}{14}$ $\frac{3}{7}$ $\frac{1}{35}$ $\frac{1}{9}$
A survey has been conducted on methods of commuter travel. Each respondent was asked to check Bus, Train and Automobile as a major method of travelling to work. More than one answer was permitted. The results reported were as follows : Bus $30$ people; Train $35$ people; ... $20$ people; and all the three methods $5$ people. How many people completed the survey form? $120$ $165$ $160$ $115$