Discussion
What will be the output of the program?
public class Case54
{
public static void main(String[] args) throws Exception
{
int flags = 20;
int top = Integer.highestOneBit(flags);
int bottom = Integer.lowestOneBit(flags);
System.out.println("top=" + top);
System.out.println("bottom=" + bottom);
}
}
Answer: B
Correct answer: top=16 then bottom=4
Twenty in binary is 10100. highestOneBit returns the value of the most significant set bit, which is 16, and lowestOneBit the value of the least significant set bit, which is 4. Both return the *value* of the bit rather than its position, which is why the answer is 16 and 4 rather than 4 and 2.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development