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

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

Description

set Bit

License

LGPL

Declaration

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

Method Source Code

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

public class Main {
    public static void setBit(byte[] data, long pos, byte val) {
        int posByte = (int) (pos / 8);
        int posBit = (int) (pos % 8);
        byte oldByte = data[posByte];
        data[posByte] = setBit(oldByte, posBit, val);
    }/*from www .j a va 2 s. c om*/

    public static byte setBit(byte data, long pos, byte val) {
        data = (byte) (((0xFF7F >> pos) & data) & 0x00FF);
        return (byte) ((val << (8 - (pos + 1))) | data);
    }
}

Related

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