Here you can find the source of setBit(int data, int bit, int value)
Parameter | Description |
---|---|
data | The number |
bit | Bit position |
value | New bit value |
public static int setBit(int data, int bit, int value)
//package com.java2s; //License from project: Open Source License public class Main { /**/* w ww.j a v a 2 s . c o m*/ * Sets bit in a number * * @param data The number * @param bit Bit position * @param value New bit value * @return The number */ public static int setBit(int data, int bit, int value) { if (value == 1) { data = data | (1 << bit); } else { data = data & ~(1 << bit); } return data; } }