Here you can find the source of setBit(byte _byte, int position, boolean value)
Parameter | Description |
---|---|
_byte | Byte where the bit will be changed |
position | Position of bit in Byte, i.e. 1 to 8 to specified value |
value | Value to be set as (True=1,False=0) |
public static byte setBit(byte _byte, int position, boolean value)
//package com.java2s; /*/*from w ww . j ava 2 s . com*/ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ public class Main { /** * Sets a bit in the byte * * @param _byte Byte where the bit will be changed * @param position Position of bit in Byte, i.e. 1 to 8 to specified value * @param value Value to be set as (True=1,False=0) * @return Byte with changed bit at specified position */ public static byte setBit(byte _byte, int position, boolean value) { position--; return (byte) (value ? _byte | 1 << position : _byte & ~(1 << position)); } }