Java Bits Convert to bitsArrayToByte(byte[] bits)

Here you can find the source of bitsArrayToByte(byte[] bits)

Description

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

License

Open Source License

Parameter

Parameter Description
bits the 8-bytes array to convert

Return

a single byte representing the "bits" array

Declaration

public static byte bitsArrayToByte(byte[] bits) 

Method Source Code

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

Related

  1. bitrv208neg(double[] a, int offa)
  2. bitrv216neg(double[] a, int offa)
  3. bitrv2conj(int n, int[] ip, double[] a, int offa)
  4. bits2float(int i)
  5. bits2Numeric(boolean[] in)
  6. bitscanForward(long bitboard)
  7. bitsCleanup(int base, int[] bits)
  8. BitsNeeded(int n)
  9. bitsRequired(double minValue, double maxValue)