Java Bit Print printBits(int number, int n)

Here you can find the source of printBits(int number, int n)

Description

print Bits

License

Open Source License

Declaration

public static String printBits(int number, int n) 

Method Source Code

//package com.java2s;

public class Main {
    public static String printBits(int number, int n) {
        String s = "";
        for (int i = 0; i < n; i++) {
            s += getBit(number, i) ? "1" : "0";
        }/*from w w  w .ja  v a 2s. com*/
        return s;
    }

    public static boolean getBit(int number, int i) {
        return (number & (1 << i)) != 0;
    }
}

Related

  1. printBitboard(long bitboard)
  2. printBitFormat(int number)
  3. printBitLong(long A)
  4. printBits(byte[] bytes)
  5. printBits(int meta)
  6. printBits(long val, int bits)
  7. printBits(long value)