List of utility methods to do Bit Set
byte | setBit(byte input, int bit) set Bit return (byte) (input | BYTE[bit]); |
byte | setBit(byte original, int bitToSet) Sets a bit to one in a byte then returns new byte return (byte) (original | (1 << bitToSet)); |
byte | setBit(byte target, byte pos) set Bit return target |= (1 << pos);
|
byte | setBit(byte v, int position, boolean value) Returns v, with the bit at position set to 1 or 0 depending on value. return (byte) setBit((int) v, position, value); |
byte | setBit(byte value, int bit, boolean on) sets the specified bit to a value if (bit < 0 || bit >= 8) throw new IllegalArgumentException("invalid bit position"); byte pos = (byte) (1 << bit); if (on) return (byte) (value | pos); else return (byte) (value & ~pos); |
byte | setBit(byte value, int bit, boolean state) Sets a single bit in a byte value return (byte) setBit((int) value, bit, state); |
byte | setBit(byte value, int bit, boolean state) Sets the given bit in the given value. return state ? (byte) (value | bit) : (byte) (value & ~bit); |
void | setBit(byte[] arr, int bit) set Bit int index = bit / 8; int bitPosition = bit % 8; arr[index] = (byte) (arr[index] | (1 << bitPosition)); |
byte[] | setBit(byte[] b, int index) Sets the bit at the specified index of b to 1. int maxIndex = b.length * 8 - 1; if ((index < 0) || (index > maxIndex)) { throw new IndexOutOfBoundsException( "Invalid bit index: " + index + " for " + b.length + "-byte array."); int byteOffset = b.length - (index / 8) - 1; int bitOffset = index % 8; byte mask = (byte) (0xFF & (1 << bitOffset)); ... |
void | setBit(byte[] ba, int bit_offset, boolean on) set Bit int byte_idx = bit_offset / 8; int bit_remainder = bit_offset % 8; byte bit_mask = (byte) ((0x1 << (7 - bit_remainder)) & 0xFF); if (on) { ba[byte_idx] |= bit_mask; } else { ba[byte_idx] &= ~bit_mask; |