List of utility methods to do Boolean Convert to
boolean[][] | boolean2array(int sz, boolean seed) booleanarray boolean[][] ret = new boolean[sz][sz]; init(ret, seed); return ret; |
byte[] | boolean2bin(boolean b) booleanbin byte[] answer = new byte[1]; answer[0] = ((b) ? TRUE : FALSE); return answer; |
byte | boolean2byte(boolean b) booleanbyte if (b) { return 1; } else { return 0; |
double | boolean2double(boolean b) Converts a Boolean value to a Double value. return b ? -1D : 0D;
|
long | boolean2long(boolean b) booleanlong return b ? -1L : 0L;
|
String | booleanArrayToBitString(final boolean[] booleanArray) Returns a bit-string representation of the given boolean array. final StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < booleanArray.length; i++) { if (booleanArray[i]) { stringBuilder.append('1'); } else { stringBuilder.append('0'); return stringBuilder.toString(); |
byte[] | booleanArrayToBytes(boolean[] input) A method that performs the same function as the booleanArrayToByte() method but is not limited by input and output size. int count = input.length / 8; if (input.length % 8 != 0) count++; byte[] out = new byte[count]; int pos = 0; int bpos = 0; while (bpos < count) { out[bpos] = 0; ... |
int | booleanArrayToInt(boolean[] in) convert an array of booleans - one ber bit to an int if (in.length > 32) throw new IllegalArgumentException("no more than 32 bits in an int"); int index = 1; int ret = 0; for (int i = 0; i < in.length; i++) { if (in[i]) ret |= index; index <<= 1; ... |
int[] | booleanArrayToIntIndexes(boolean[] arrb) Set elements of arrb true if their indexes appear in arrb. int count = 0; for (int i = 0; i < arrb.length; i++) { if (arrb[i]) { count++; int[] intarr = new int[count]; count = 0; ... |
String | booleanArrayToString(boolean[] array) Creates a string representation of the given array of type boolean[]. StringBuffer sb = new StringBuffer(); sb.append("["); for (boolean a : array) { sb.append((a ? 1 : 0) + ", "); if (sb.lastIndexOf(", ") != -1) sb.delete(sb.lastIndexOf(", "), sb.length()); sb.append("]"); ... |