Java Byte to Bit byteToBitsArray(byte b)

Here you can find the source of byteToBitsArray(byte b)

Description

This method convert a single byte to a 8-bytes array.

License

Open Source License

Parameter

Parameter Description
b the byte to be converted

Return

a 8-bytes array representing the binary value of parameter b

Declaration

public static byte[] byteToBitsArray(byte b) 

Method Source Code

//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;
    }
}

Related

  1. byteToBits(byte b)
  2. byteToBits(byte b)
  3. byteToBits(byte b)
  4. byteToBits(byte b)
  5. byteToBits(byte b)
  6. byteToBitStr(byte b)