List of utility methods to do Bit String From
char | toBit(boolean f) to Bit return f ? '1' : '0'; |
boolean | toBit(byte value, int index) to Bit return ((value >>> (7 - index)) & 1) > 0;
|
int | toBitMask(int numBits) to Bit Mask return twoToThePowerOf(numBits) - 1;
|
boolean[] | toBits(final byte b) Convert a byte to a 8 bits boolean[] bits = new boolean[8]; for (int i = 0; i < bits.length; i++) { bits[i] = ((b & (1 << i)) != 0); return bits; |
String | toBits(int b) to Bits return Integer.toBinaryString(b).replace(' ', '0'); |
String | toBits(int b) to Bits return toBits(b, 8);
|
boolean[] | toBits(long value, int length) transform a long value into a boolean array boolean[] bits = new boolean[length]; for (int i = length - 1; i >= 0; i--) { bits[i] = (value & (1 << i)) != 0; return bits; |
boolean[] | toBitsArray(byte[] bytes, int bitCount) to Bits Array boolean[] dst = new boolean[bitCount]; for (int i = 0; i < dst.length; i++) { dst[i] = (bytes[i / 8] & (1 << (i % 8))) != 0; return dst; |
String | toBitString(byte value) to Bit String char[] chars = new char[8]; int mask = 1; for (int i = 0; i < 8; ++i) { chars[7 - i] = (value & mask) != 0 ? '1' : '0'; mask <<= 1; return new String(chars); |
String | toBitString(byte[] bytes) to Bit String StringBuilder sb = new StringBuilder(); boolean skip = true; for (byte b : bytes) { if (b == 0 && skip) { } else { skip = false; for (int i = 7; i >= 0; i--) { sb.append((b >> i) & 1); ... |