How do you find if a number is power of two, without using arithmetic operator?
Submitted by: MuhammadAssume its a question about using bitwise operator as soon as you hear restriction about not allowed to use arithmetic operator. If that restriction is not in place then you can easily check if a number is power of two by using modulus and division operator. By the using bitwise operator, there is a nice trick to do this. You can use following code to check if a number if power of two or not
public static boolean powerOfTwo(int x) {
return (x & (x - 1)) == 0;
}
x & (x-1) is a nice trick to convert right most bit to zero if it's on, I learned from hackers delight book.
Submitted by: Muhammad
public static boolean powerOfTwo(int x) {
return (x & (x - 1)) == 0;
}
x & (x-1) is a nice trick to convert right most bit to zero if it's on, I learned from hackers delight book.
Submitted by: Muhammad
Read Online Analyst Integration Job Interview Questions And Answers
Top Analyst Integration Questions
☺ | If I have a Web application that I find is still running (via top/ps/whatever) but users are getting "connection refused" when trying to access it, how would I go about diagnosing the problem? |
☺ | What is Data mapping? |
☺ | Explain what is Data Integration? |
☺ | Explain about Data Integration hierarchy? |
☺ | What is Business plan? |
Top Analysis Categories
☺ | GIS Interview Questions. |
☺ | Statistics Interview Questions. |
☺ | Financial Analyst Interview Questions. |
☺ | GIS Analysis Interview Questions. |
☺ | Data Analyst Interview Questions. |