Java Bit Clean clearBit(int flag, int i)

Here you can find the source of clearBit(int flag, int i)

Description

clear Bit

License

Open Source License

Return

`flag' with bit `i' set to 0

Declaration

public static final int clearBit(int flag, int i) 

Method Source Code

//package com.java2s;
/*//from w w  w.  j a  v  a 2s.  c o  m
 * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

public class Main {
    /**
     * @return `flag' with bit `i' set to 0
     */
    public static final int clearBit(int flag, int i) {
        int bit = pow2(i);
        return (flag & bit) == 0 ? flag : flag ^ bit;
    }

    private static final int pow2(int n) {
        return 1 << n;
    }
}

Related

  1. clearBit(byte b, int i)
  2. clearBit(byte input, int bit)
  3. clearBit(byte v, int position)
  4. clearBit(int bits, int index)
  5. clearBit(int n, int bitPosition)
  6. clearBit(int value, int bit)
  7. clearBit(int value, int bit)
  8. clearBit(int value, int bitIndex)