Java Bit Clean clearBit(int value, int bit)

Here you can find the source of clearBit(int value, int bit)

Description

Clear the bit within the int.

License

Apache License

Parameter

Parameter Description
value The value in which the bit is to be cleared.
bit The bit to clear.

Return

The value with the bit cleared.

Declaration

public static int clearBit(int value, int bit) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from w  ww .  j  a  v  a  2  s. c  o  m*/
     * Clear the bit within the int.
     * @param value The value in which the bit is to be cleared.
     * @param bit The bit to clear.
     * @return The value with the bit cleared.
     */
    public static int clearBit(int value, int bit) {
        assert bit >= 0 && bit < 16;
        return value & ~bitMask(bit);
    }

    /**
     * Clear the bit within the byte.
     * @param value The value in which the bit is to be cleared.
     * @param bit The bit to clear.
     * @return The value with the bit cleared.
     */
    public static byte clearBit(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;
    }
}

Related

  1. clearBit(byte v, int position)
  2. clearBit(int bits, int index)
  3. clearBit(int flag, int i)
  4. clearBit(int n, int bitPosition)
  5. clearBit(int value, int bit)
  6. clearBit(int value, int bitIndex)
  7. clearBit(int value, int index)
  8. clearBit(long n, int i)
  9. clearBit33ofDTS(byte[] array, int offset)