Here you can find the source of getBit(byte[] bytes, int bitNr)
Parameter | Description |
---|---|
bytes | a parameter |
bitNr | a parameter |
public static int getBit(byte[] bytes, int bitNr)
//package com.java2s; /**/* w w w . j a v a 2 s . co m*/ * Source obtained from crypto-gwt. Apache 2 License. * https://code.google.com/p/crypto-gwt/source/browse/crypto-gwt/src/main/java/com/googlecode/ * cryptogwt/util/ByteArrayUtils.java */ public class Main { /** * Get the given bit in the encoded bytes. Note: bit 0 is assumed to be the LSB. * * @param bytes * @param bitNr * @return */ public static int getBit(byte[] bytes, int bitNr) { int byteNr = bytes.length - (bitNr / 8) - 1; int bitNrInByte = bitNr % 8; return bytes[byteNr] >>> bitNrInByte & 1; } }