Java Bit Set setBit(byte[] data, int pos, int val)

Here you can find the source of setBit(byte[] data, int pos, int val)

Description

set Bit

License

Apache License

Declaration

public static void setBit(byte[] data, int pos, int val) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static void setBit(byte[] data, int pos, int val) {
        int posByte = pos / 8;
        int posBit = pos % 8;
        byte oldByte = data[posByte];
        oldByte = (byte) (((0xFF7F >> posBit) & oldByte) & 0x00FF);
        byte newByte = (byte) ((val << (8 - (posBit + 1))) | oldByte);
        data[posByte] = newByte;//from ww w. j  ava 2  s .c  om
    }
}

Related

  1. setBit(byte[] bytes, int bitNr, int bit)
  2. setBit(byte[] bytes, int off, boolean v)
  3. setBit(byte[] data, int index, boolean value)
  4. setBit(byte[] data, int pos, boolean val)
  5. setBit(byte[] data, int pos, int val)
  6. setBit(byte[] data, long pos, byte val)
  7. setBit(final byte input, final int bit, final boolean status)
  8. setBit(final byte pData, final int pBitIndex, final boolean pOn)
  9. setBit(final byte[] buf, final long bitIndex, final boolean value)