Java examples for java.lang:long
is Bit Set in long value
/**/* w w w. j a v a 2s .c o m*/ * JMongo is a mongodb driver writtern in java. * Copyright (C) 2010 Xiaohu Huang * * JMongo is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * JMongo is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with JMongo. If not, see <http://www.gnu.org/licenses/>. */ //package com.java2s; public class Main { public static void main(String[] argv) throws Exception { long holder = 2; int i = 2; System.out.println(isBitSet(holder, i)); } public static boolean isBitSet(long holder, int i) { if (i < 0 || i > 63) { throw new IllegalArgumentException( "i should from 0 inclusive and 64 exclusive"); } return (holder & (1 << i)) > 0; } }