Java Bit Clean clearBit(int n, int bitPosition)

Here you can find the source of clearBit(int n, int bitPosition)

Description

Clears bit position in a copy of the integer and returns it

License

Open Source License

Parameter

Parameter Description
n The integer
bitPosition position of bit in binary representation 1 thru 32 ( 1 is the least significant and 32 is the most

Return

a copy of the integer with the bit cleared in that position

Declaration

public static final int clearBit(int n, int bitPosition) 

Method Source Code

//package com.java2s;
/*/*from w ww  .  j  a  v a2  s  .  co m*/
Copyright (C) 1996, 1997, 1998 State of California, Department of 
Water Resources.
    
VISTA : A VISualization Tool and Analyzer. 
   Version 1.0beta
   by Nicky Sandhu
California Dept. of Water Resources
Division of Planning, Delta Modeling Section
1416 Ninth Street
Sacramento, CA 95814
(916)-653-7552
nsandhu@water.ca.gov
    
Send bug reports to nsandhu@water.ca.gov
    
This program is licensed to you under the terms of the GNU General
Public License, version 2, as published by the Free Software
Foundation.
    
You should have received a copy of the GNU General Public License
along with this program; if not, contact Dr. Francis Chung, below,
or the Free Software Foundation, 675 Mass Ave, Cambridge, MA
02139, USA.
    
THIS SOFTWARE AND DOCUMENTATION ARE PROVIDED BY THE CALIFORNIA
DEPARTMENT OF WATER RESOURCES AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE CALIFORNIA
DEPARTMENT OF WATER RESOURCES OR ITS CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OR SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
    
For more information about VISTA, contact:
    
Dr. Francis Chung
California Dept. of Water Resources
Division of Planning, Delta Modeling Section
1416 Ninth Street
Sacramento, CA  95814
916-653-5601
chung@water.ca.gov
    
or see our home page: http://wwwdelmod.water.ca.gov/
    
Send bug reports to nsandhu@water.ca.gov or call (916)-653-7552
    
 */

public class Main {
    /**
     * Clears bit position in a copy of the integer and returns it
     * 
     * @param n
     *            The integer
     * @param bitPosition
     *            position of bit in binary representation 1 thru 32 ( 1 is the
     *            least significant and 32 is the most
     * @return a copy of the integer with the bit cleared in that position
     */
    public static final int clearBit(int n, int bitPosition) {
        int number = n;
        int bitNumber = ~(1 << (bitPosition - 1));
        return (number & bitNumber);
    }
}

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 flag, int i)
  6. clearBit(int value, int bit)
  7. clearBit(int value, int bit)
  8. clearBit(int value, int bitIndex)
  9. clearBit(int value, int index)