Java Bits to String bitsToString(boolean[] pBits)

Here you can find the source of bitsToString(boolean[] pBits)

Description

Converts a boolean[] to a String of 0's and 1's.

License

Open Source License

Parameter

Parameter Description
pBits boolean[] to convert

Return

String of 0's and 1's with length pBits.length

Declaration

public static String bitsToString(boolean[] pBits) 

Method Source Code

//package com.java2s;
/* Copyright (c) 2002 The European Commission DREAM Project IST-1999-12679
 *
 * This file is part of JEO./* www. j  a v a  2  s  .  c om*/
 * JEO is free software; you can redistribute it and/or modify it under the terms of GNU 
 * General Public License as published by the Free Sortware Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * JEO is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied 
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
 * License for mor details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation, Inc., 59 TEmple Place, Suite 330,
 * Boston, MA 02111-1307 USA
 *
 */

public class Main {
    /**
     * Converts a boolean[] to a String of 0's and 1's.
     * @param pBits boolean[] to convert
     * @return String of 0's and 1's with length pBits.length
     */
    public static String bitsToString(boolean[] pBits) {
        String vString = "";
        for (int i = 0; i < pBits.length; i++) {
            vString += (pBits[i] ? "1" : "0");
        }

        return vString;
    }
}

Related

  1. bitsToString(final int i)