get Bit from long value - Java Language Basics

Java examples for Language Basics:Bit

Description

get Bit from long value

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        long bitmap = 2;
        int pos = 2;
        System.out.println(getBit(bitmap, pos));
    }/* www  .  ja v  a  2 s.co m*/

    public static boolean getBit(long bitmap, int pos) {
        return ((1 << pos) & bitmap) != 0;
    }
}

Related Tutorials