Java Bit Set setBit(int[] x, int i, int v)

Here you can find the source of setBit(int[] x, int i, int v)

Description

Used to set or clear a bit in an int array

License

Open Source License

Parameter

Parameter Description
x int array
i offset
v if odd, set; else, clear

Declaration

public static void setBit(int[] x, int i, int v) 

Method Source Code

//package com.java2s;
//    it under the terms of the GNU Lesser General Public License as published

public class Main {
    /**//  w ww . ja  v a 2 s .c om
     * Used to set or clear a bit in an int array
     * @param x int array
     * @param i offset
     * @param v if odd, set; else, clear
     */
    public static void setBit(int[] x, int i, int v) {
        if ((v & 0x01) == 1)
            x[i / 32] |= 1 << (i % 32); // set bit
        else
            x[i / 32] &= ~(1 << (i % 32)); // clear bit
    }
}

Related

  1. setBit(int value, int bit)
  2. setBit(int value, int bitIndex)
  3. setBit(int value, int bitmask, boolean set)
  4. setBit(int value, int flags)
  5. setBit(int value, int index)
  6. setBit(long[] data, int position, int bitWidth)
  7. setBit(short shortIn, int bitPos)
  8. setBitAt(byte flags, int pos, boolean value)
  9. setBitAt(int bitIndex, boolean value, byte b)