Convert a byte into a bit-flagged array





1
Date Submitted Sat. Jun. 7th, 2008 5:06 PM
Revision 1 of 1
Beginner me
Tags bit | byte | Convert
Comments 0 comments
Output is a boolean array of the size 8 where true is for "1" and false for "0"

public static boolean[] convertToBits(byte b) {
        boolean[] bits = new boolean[8];
        for (int i = 0; i < bits.length; i++) {
            bits[7 - i] = ((b & (1 << i)) != 0);
        }
        return bits;
    }
 

foo bar

Comments

There are currently no comments for this snippet.

Voting

Votes Up


Newbie kengursasa

Votes Down