Java Bit Set setBit(byte[] byteArray, int index)

Here you can find the source of setBit(byte[] byteArray, int index)

Description

set Bit

License

Open Source License

Declaration

public static void setBit(byte[] byteArray, int index) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static void setBit(byte[] byteArray, int index) {
        if (index >= byteArray.length * 8 || index < 0) {
            throw new ArrayIndexOutOfBoundsException();
        }/*from   w  ww.j  a  va  2  s  .co m*/

        int arrayIndex = index / 8;
        index = index % 8;
        byte tmpByte = (byte) (0x80 >>> index);
        byteArray[arrayIndex] = (byte) (byteArray[arrayIndex] | tmpByte);
    }
}

Related

  1. setBit(byte value, int bit, boolean state)
  2. setBit(byte value, int bit, boolean state)
  3. setBit(byte[] arr, int bit)
  4. setBit(byte[] b, int index)
  5. setBit(byte[] ba, int bit_offset, boolean on)
  6. setBit(byte[] bytes, int bitNr, int bit)
  7. setBit(byte[] bytes, int off, boolean v)
  8. setBit(byte[] data, int index, boolean value)
  9. setBit(byte[] data, int pos, boolean val)