Java Bit Set setBit(byte[] bytes, int bitNr, int bit)

Here you can find the source of setBit(byte[] bytes, int bitNr, int bit)

Description

set Bit

License

Apache License

Declaration

public static void setBit(byte[] bytes, int bitNr, int bit) 

Method Source Code

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

public class Main {
    public static void setBit(byte[] bytes, int bitNr, int bit) {
        int byteNr = bytes.length - (bitNr / 8) - 1;
        int bitNrInByte = bitNr % 8;
        if (bit != 0) {
            bytes[byteNr] |= 1 << bitNrInByte;
        } else {/*from  ww  w. j a v  a 2s. co  m*/
            bytes[byteNr] &= ~(1 << bitNrInByte);
        }
    }
}

Related

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