Java Bit String From toBits(int b)

Here you can find the source of toBits(int b)

Description

to Bits

License

Open Source License

Declaration

public static final String toBits(int b) 

Method Source Code

//package com.java2s;

public class Main {
    /** @see #toBits(int) */
    private static String onBit = "*";
    /** @see #toBits(int) */
    private static String offBit = ".";

    public static final String toBits(int b) {
        return toBits(b, 8);
    }/*from   www  . j a  v  a  2 s  . co m*/

    public static final String toBits(int b, int n) {
        int mask = 0x0001 << (n - 1);
        //Debug.println(toHex8(mask));
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            sb.append((b & (mask >>> i)) != 0 ? onBit : offBit);
            //Debug.println(toHex8(mask >>> i));
        }
        return sb.toString();
    }
}

Related

  1. toBit(boolean f)
  2. toBit(byte value, int index)
  3. toBitMask(int numBits)
  4. toBits(final byte b)
  5. toBits(int b)
  6. toBits(long value, int length)
  7. toBitsArray(byte[] bytes, int bitCount)
  8. toBitString(byte value)
  9. toBitString(byte[] bytes)