get Bit from Byte value - Java File Path IO

Java examples for File Path IO:Byte Array

Description

get Bit from Byte value

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        byte b = 2;
        int pos = 2;
        System.out.println(getBit(b, pos));
    }/*  ww w . j ava2 s.  c o m*/

    /**
     *
     * @param b
     * @param pos
     * @return
     */
    public static boolean getBit(byte b, int pos) {
        return (b & (1 << pos)) > 0;
    }
}

Related Tutorials