Here you can find the source of bitToBoolean(final byte value, final int bitNbr)
byte
as boolean
.
Parameter | Description |
---|---|
value | The <code>byte</code> value |
bitNbr | The specific bit in the <code>byte</code>, from 0 to 7 |
boolean
.
public static boolean bitToBoolean(final byte value, final int bitNbr)
//package com.java2s; /**/*from w ww . j ava2 s .c o m*/ * jModuleConnect is an framework for communication and file management on modem * modules. * * This project was inspired by the project TC65SH * by Christoph Vilsmeier: <http://www.vilsmeier-consulting.de/tc65sh.html> * * Copyright (C) 2015 sitec systems GmbH <http://www.sitec-systems.de> * * This file is part of jModuleConnect. * * jModuleConnect is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your option) * any later version. * * jModuleConnect 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with jModuleConnect. If not, see <http://www.gnu.org/licenses/>. */ public class Main { private final static byte[] BIT = new byte[] { (byte) 0x01, (byte) 0x02, (byte) 0x04, (byte) 0x08, (byte) 0x010, (byte) 0x20, (byte) 0x40, (byte) 0x80 }; /** * Gets the bit state of a specific bit from a <code>byte</code> as <code> * boolean</code>. * @param value The <code>byte</code> value * @param bitNbr The specific bit in the <code>byte</code>, from 0 to 7 * @return The bit state as <code>boolean</code>. * @since 1.0 */ public static boolean bitToBoolean(final byte value, final int bitNbr) { if (bitNbr < 0 || bitNbr > 7) { throw new IllegalArgumentException("Parameter bitNbr is out of range (0-7)"); } return (value & BIT[bitNbr]) != 0; } }