is Bit Set - Android java.lang

Android examples for java.lang:Integer

Description

is Bit Set

Demo Code

//package com.java2s;

public class Main {
    public static boolean isBitSet(byte[] arr, int bit) {
        int index = bit / 8; // Get the index of the array for the byte with this bit
        int bitPosition = bit % 8; // Position of this bit in a byte

        return (arr[index] >> bitPosition & 1) == 1;
    }//from   w  w w. j ava2  s  . c o  m
}

Related Tutorials