Here you can find the source of byteToBitsArray(byte b)
Parameter | Description |
---|---|
b | the byte to be converted |
public static byte[] byteToBitsArray(byte b)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w ww . j a va2 s .c om*/ * This method convert a single byte to a 8-bytes array. * @param b the byte to be converted * @return a 8-bytes array representing the binary value of parameter b */ public static byte[] byteToBitsArray(byte b) { byte[] result = new byte[8]; short val = (short) (b + 128); for (int i = 0; i < 8; i++) { result[7 - i] = (byte) (val % 2); val /= 2; } return result; } }