Java Bits Convert to bitString(byte b)

Here you can find the source of bitString(byte b)

Description

bit String

License

Apache License

Declaration

public static String bitString(byte b) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static String bitString(byte b) {
        StringBuilder buff = new StringBuilder();
        boolean[] array = byteToBitArray(b);
        for (int i = 0; i < array.length; i++) {
            buff.append(array[i] ? 1 : 0);
        }/*w  w  w  .ja v a2  s . co  m*/
        return buff.toString();
    }

    public static boolean[] byteToBitArray(byte b) {
        boolean[] buff = new boolean[8];
        int index = 0;
        for (int i = 7; i >= 0; i--) {
            buff[index++] = ((b >>> i) & 1) == 1;
        }
        return buff;
    }
}

Related

  1. bitsToDouble(String bits, double min, double max, int splits)
  2. bitsToFloats(boolean[] b)
  3. bitsToTransform(int src, int target)
  4. bitStr(long value)
  5. bitString(boolean value)
  6. bitString2byte(String str)
  7. bitStringToInt(String bits, char one)
  8. bitsUsed(long value)
  9. bitTest(String value, int pos)