Here you can find the source of toBinaryString(final boolean[] bits)
Parameter | Description |
---|---|
bits | Array of booleans to interpret |
public static String toBinaryString(final boolean[] bits)
//package com.java2s; public class Main { private static final int TRUE = 1; private static final int FALSE = 0; /**// www .ja va2s .co m * Converts an array of boolean into a string using the toDigit method. * * @param bits * Array of booleans to interpret * @return String, containing binary digits that represent the array */ public static String toBinaryString(final boolean[] bits) { final StringBuilder builder = new StringBuilder(bits.length); for (final boolean bit : bits) { builder.append(toDigit(bit)); } return builder.toString(); } /** * Converts a boolean into a digit. * * @param bit * the boolean to interpret * @return 1, if bit was <code>true</code>, 0 otherwise */ public static int toDigit(final boolean bit) { return (bit) ? TRUE : FALSE; } }