Android 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;
/**/*from  www  .  j a  va 2s.co  m*/
 * Source obtained from crypto-gwt. Apache 2 License.
 * https://code.google.com/p/crypto-gwt/source/browse/crypto-gwt/src/main/java/com/googlecode/
 * cryptogwt/util/ByteArrayUtils.java
 */

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 {
            bytes[byteNr] &= ~(1 << bitNrInByte);
        }
    }
}

Related

  1. setBit(byte bite, int offset, boolean set)
  2. setBit(byte bits, int offset, boolean status)
  3. resetBit(byte b, int bit)
  4. setBit(byte[] arr, int bit)
  5. reverseBits(byte[] bits)
  6. bitwiseNot(int number)
  7. xor(byte[]... arrays)
  8. xorArray(byte[] array, byte[] mask)