The Gateway to Computer Science Excellence
0 votes
125 views

UGCNET-DEC2018-II-49.8

  1. UGCNET-DEC2018-II-245
  2. UGCNET-DEC2018-II-245
  3. UGCNET-DEC2018-II-245
  4. UGCNET-DEC2018-II-245

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 & i);
        a=a >>>1; // This is 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 Others by Veteran (425k points)
edited by | 125 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
by (69 points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,645 questions
56,578 answers
195,771 comments
101,771 users