search
Log In
0 votes
295 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
in Unknown Category
edited by
295 views
0

option B.

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

1 Answer

0 votes
C is the correct Answer

Related questions

1 vote
1 answer
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
asked Jan 2, 2019 in Unknown Category Arjun 1.1k views
0 votes
2 answers
2
646 views
Match List-I with List-II and choose the correct answer from the code given below : ... iii), (d)-(iv) (a)-(iii), (b)-(iv), (c)-(ii), (d)-(i) (a)-(iv), (b)-(iii), (c)-(ii), (d)-(i)
asked Jan 2, 2019 in Unknown Category Arjun 646 views
1 vote
1 answer
3
878 views
​​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}$
asked Jan 2, 2019 in Unknown Category Arjun 878 views
0 votes
2 answers
4
718 views
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$
asked Jan 2, 2019 in Unknown Category Arjun 718 views
...