Here you can find the source of setBit(int b0, boolean value, int original)
Parameter | Description |
---|---|
b0 | Which bit, LSB is 0 |
value | What to set it to |
original | The integer to set the bit for |
public static int setBit(int b0, boolean value, int original)
//package com.java2s; //License from project: Creative Commons License public class Main { /**//from ww w . j a v a 2 s .com * Sets n-th bit for the given integer * @param b0 Which bit, LSB is 0 * @param value What to set it to * @param original The integer to set the bit for * @return Int with the n-th bit set */ public static int setBit(int b0, boolean value, int original) { if (getBit(b0, original) != value) { int mask = (1 << b0); return original ^ mask; } return original; } /** * Returns n-th bit from an integer * @param b0 which bit * @param number The integer in question * @return Returns the bit */ public static boolean getBit(int b0, int number) { return ((number >> b0) & 1) == 1; } }