Here you can find the source of setBit(int value, int bit)
Parameter | Description |
---|---|
value | The value in which to set the bit. |
bit | The bit to set. |
public static int setBit(int value, int bit)
//package com.java2s; //License from project: Apache License public class Main { /**/* w ww. j a v a 2 s .c o m*/ * Set the bit within the int. * @param value The value in which to set the bit. * @param bit The bit to set. * @return The new value with the bit set. */ public static int setBit(int value, int bit) { assert bit >= 0 && bit < 16; return value | bitMask(bit); } /** * Set the bit within the byte. * @param value The value in which to set the bit. * @param bit The bit to set. * @return The new value with the bit set. */ public static byte setBit(byte value, int bit) { assert bit >= 0 && bit < 16; return (byte) (value | bitMask(bit)); } /** * Calculate a bitmask of the bit. * @param bit The bit to be used to calculate the bitmask. * @return The value of the bitmask. */ public static int bitMask(int bit) { assert bit >= 0 && bit < 16; return 1 << bit; } }