Java Bits Convert to bitTest(String value, int pos)

Here you can find the source of bitTest(String value, int pos)

Description

Bit Test - test the bit for the given position in the given string Passing pos = 0 and value = "100" would yield false Passing pos = 1 and value = "100" would yield false Passing pos = 2 and value = "100" would yield true

License

Open Source License

Declaration

public static final boolean bitTest(String value, int pos) 

Method Source Code

//package com.java2s;
/*//w  ww.j a va2 s  .  co  m
Copyright (c) 1996-2013 Ariba, Inc.
All rights reserved. Patents pending.
    
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
    
$Id: //ariba/platform/util/core/ariba/util/core/StringUtil.java#41 $
*/

public class Main {
    /**
    Bit Test  - test the bit for the given position in the given string
    Passing pos = 0 and value = "100" would yield false
    Passing pos = 1 and value = "100" would yield false
    Passing pos = 2 and value = "100" would yield true
        
    @aribaapi private
    */
    public static final boolean bitTest(String value, int pos) {
        int valueLength = value.length();
        if (pos >= valueLength) {
            return false;
        }
        int charPos = valueLength - pos - 1;
        char bit = value.charAt(charPos);
        return (bit == '1');
    }
}

Related

  1. bitString(boolean value)
  2. bitString(byte b)
  3. bitString2byte(String str)
  4. bitStringToInt(String bits, char one)
  5. bitsUsed(long value)
  6. bitToBoolean(byte b)
  7. bitToBoolean(final byte value, final int bitNbr)
  8. bitToLong(byte[] bytes, int offset, int length)
  9. bitToLong(byte[] bytes, int offset, int length)