Here you can find the source of setBitAt(int offset, boolean bitValue, byte aByte)
Parameter | Description |
---|---|
offset | The bit offset within the byte. |
bitValue | The bit value to set. |
aByte | A byte of bits. |
public static byte setBitAt(int offset, boolean bitValue, byte aByte)
//package com.java2s; //License from project: Apache License public class Main { /**//from www.j a v a2 s .c o m * Set a bit within a byte. * * @param offset The bit offset within the byte. * @param bitValue The bit value to set. * @param aByte A byte of bits. * @return A new byte with the settings applied. */ public static byte setBitAt(int offset, boolean bitValue, byte aByte) { return (byte) ((bitValue) ? (aByte | (1 << offset)) : (aByte & ~(1 << offset))); } }