Android Bit Set setBit(byte[] arr, int bit)

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

Description

set Bit

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;

public class Main {
    public static void setBit(byte[] arr, int bit) {
        int index = bit / 8; // Get the index of the array for the byte with this bit
        int bitPosition = bit % 8; // Position of this bit in a byte

        arr[index] = (byte) (arr[index] | (1 << bitPosition));
    }//  www . j  a v  a 2  s  .  co m
}

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[] bytes, int bitNr, int bit)
  5. reverseBits(byte[] bits)
  6. bitwiseNot(int number)
  7. xor(byte[]... arrays)