Java Bits Convert to bit(byte[] h, int i)

Here you can find the source of bit(byte[] h, int i)

Description

Get the i'th bit of a byte array.

License

Creative Commons License

Parameter

Parameter Description
h the byte array.
i the bit index.

Return

0 or 1, the value of the i'th bit in h

Declaration

public static int bit(byte[] h, int i) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from w  ww .  j a  v a2s  . co m
     * Get the i'th bit of a byte array.
     *
     * @param h the byte array.
     * @param i the bit index.
     * @return 0 or 1, the value of the i'th bit in h
     */
    public static int bit(byte[] h, int i) {
        return (h[i >> 3] >> (i & 7)) & 1;
    }
}

Related

  1. bit(int a, int b)
  2. bit(int row, int col)
  3. BIT(int x)
  4. bitArray2byte(boolean[] array)