Answers for "reverse bits java"

0

reverse bits java

public class MyClass {

    // function to reverse bits of a number
    public static int reverseBits(int n)  {
        int rev = 0;
        while (n > 0) {
            rev <<= 1;
            if ((int)(n & 1) == 1)
                rev ^= 1;
            n >>= 1;
        }
        return rev;
    }
 
    public static void main(String[] args)  {
        int n = 11;
        System.out.println(reverseBits(n));
    }
}
Posted by: Guest on June-02-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language