Converts a little endian boolean array representing bits into an Integer - Java java.lang

Java examples for java.lang:int Binary

Description

Converts a little endian boolean array representing bits into an Integer

Demo Code


//package com.java2s;

public class Main {
    /**/*  w w w .  j ava 2  s.c  om*/
     * Converts a little endian boolean array representing bits into an {@link Integer}
     * 
     * @param bits - little endian boolean array
     * @return appropriate {@link Integer}
     */
    public static int bytesToInt(boolean[] bits) {
        int sum = 0;
        int multiplier = 1;
        for (boolean b : bits) {
            if (b) {
                sum += multiplier;
            }
            multiplier *= 2;
        }
        return sum;
    }
}

Related Tutorials