Here you can find the source of bitsArrayToByte(byte[] bits)
Parameter | Description |
---|---|
bits | the 8-bytes array to convert |
public static byte bitsArrayToByte(byte[] bits)
//package com.java2s; //License from project: Open Source License public class Main { /**// w w w.j a v a2 s.c o m * This method convert a 8-bytes array to a single byte. * It assume that the array contains only 1's or 0's * @param bits the 8-bytes array to convert * @return a single byte representing the "bits" array */ public static byte bitsArrayToByte(byte[] bits) { byte temp = 0; for (int i = 0; i < bits.length; i++) { temp |= bits[i] << (7 - i); } return (byte) (temp + 128); } }