Here you can find the source of setBitBiInt(int b0, int b1, int value, int original)
Parameter | Description |
---|---|
b0 | First bit. |
b1 | Second bit. |
value | 0-3 int. |
original | Original int to modify. |
public static int setBitBiInt(int b0, int b1, int value, int original)
//package com.java2s; //License from project: Creative Commons License public class Main { /**//from w ww . java 2 s .c o m * Sets an int into another int. * @param b0 First bit. * @param b1 Second bit. * @param value 0-3 int. * @param original Original int to modify. * @return Modified int. */ public static int setBitBiInt(int b0, int b1, int value, int original) { original = setBit(b0, getBit(0, value), original); original = setBit(b1, getBit(1, value), original); return original; } /** * 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; } }