Java Bit Set setBit(final long word, final int idx, final boolean bit)

Here you can find the source of setBit(final long word, final int idx, final boolean bit)

Description

set Bit

License

Open Source License

Declaration

public static long setBit(final long word, final int idx, final boolean bit) 

Method Source Code

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

public class Main {
    public static long setBit(final long word, final int idx, final boolean bit) {
        if (bit)/*from  w w w. ja  va  2 s . c o  m*/
            return setBitTo1(word, idx);
        return setBitTo0(word, idx);
    }

    private static long setBitTo1(final long word, final int idx) {
        return ((1l << idx) | word);
    }

    private static long setBitTo0(final long word, final int idx) {
        return (~(1l << idx) & word);
    }
}

Related

  1. setBit(final byte input, final int bit, final boolean status)
  2. setBit(final byte pData, final int pBitIndex, final boolean pOn)
  3. setBit(final byte[] buf, final long bitIndex, final boolean value)
  4. setbit(final int num, final int bitnum, final boolean state)
  5. setBit(final int source, final int bit, final boolean value)
  6. setBit(int b0, boolean value, int original)
  7. setBit(int bit)
  8. setBit(int bitmask, int bit, boolean enabled)
  9. setBit(int bits, int index)