com.ibm.eou.decimal
Class BitString

java.lang.Object
  |
  +--com.ibm.eou.decimal.BitString

public class BitString
extends java.lang.Object

This class represents a field of binary bits, and provides some fundamental operations on them. Instances are delivered as the result of decimal encoding methods on DecimalEncoder, and may be supplied as parameters to decimal decoding methods on DecimalDecoder.

Author:
Dave Clark, IBM Ease of Use

Field Summary
(package private)  byte[] fBits
           
(package private)  int fNumberOfBits
           
 
Constructor Summary
BitString(int numberOfBits)
          Create a new field of bits, with all bits initially reset and untouched.
 
Method Summary
static BitString createFromBinary(java.lang.String bitpattern)
          Create a new field of bits using the bit values stored in a string as 1s or 0s.
static BitString createFromHexadecimal(java.lang.String hexpattern)
          Create a new field of bits using the nybble values stored in a string as hexadecimal digits.
 boolean equals(java.lang.Object obj)
          Return true if the supplied argument is a bit string equal to this bit string, ie having the same number of bits and all matching bit settings.
 void fillBits(int startbit, boolean value)
          Fill a range of bits, from the start bit to the end of the bit field, with the specified value.
 void fillBits(int startbit, int bits, boolean value)
          Fill a range of bits with the specified value.
 boolean getBit(int bit)
          Extract a bit.
 int getBits(int startbit, int bits)
          Extract a range of bits (up to 32 of them).
 int getNumberOfBits()
          Return the number of bits in the field.
 void resetBit(int bit)
          Reset the specified bit.
 void setBit(int bit)
          Set the specified bit.
 void storeBit(int bit, boolean value)
          Store a bit.
 void storeBits(int startbit, int bits, int values)
          Store a range of bits (up to 32 of them).
 java.lang.String toBitString()
          Render the bit field as a string of 1s and 0s.
 java.lang.String toHexString()
          Render the bit field as a string of hexadecimal digits, each representing four bits (one nybble) from the field.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fNumberOfBits

final int fNumberOfBits

fBits

final byte[] fBits
Constructor Detail

BitString

public BitString(int numberOfBits)
Create a new field of bits, with all bits initially reset and untouched.

Method Detail

createFromBinary

public static BitString createFromBinary(java.lang.String bitpattern)
Create a new field of bits using the bit values stored in a string as 1s or 0s. A character '1' in the string is taken to be a 1 bit (touched), a character '0' in the string is taken to be a 0 bit (touched), and any other character is taken to be a 0 bit (untouched). The length of the string is taken as the number of bits in the field.


createFromHexadecimal

public static BitString createFromHexadecimal(java.lang.String hexpattern)
Create a new field of bits using the nybble values stored in a string as hexadecimal digits. A character '0' to 'f' in the string is taken to be four bits (touched), and any other character is taken to be four 0 bits (untouched). Four times the length of the string is taken as the number of bits in the field.


getNumberOfBits

public int getNumberOfBits()
Return the number of bits in the field.


resetBit

public void resetBit(int bit)
Reset the specified bit.


setBit

public void setBit(int bit)
Set the specified bit.


storeBit

public void storeBit(int bit,
                     boolean value)
Store a bit.


storeBits

public void storeBits(int startbit,
                      int bits,
                      int values)
Store a range of bits (up to 32 of them). The lowest bits of the supplied values are used, with the highest of those bits being stored at startbit, and each lower bit in turn being stored at successive bits in the field.


fillBits

public void fillBits(int startbit,
                     int bits,
                     boolean value)
Fill a range of bits with the specified value.


fillBits

public void fillBits(int startbit,
                     boolean value)
Fill a range of bits, from the start bit to the end of the bit field, with the specified value.


getBit

public boolean getBit(int bit)
Extract a bit.


getBits

public int getBits(int startbit,
                   int bits)
Extract a range of bits (up to 32 of them). The bits are returned in the lowest bits of the returned value, with the highest of those being the bit at startbit, and each lower bit being successive bits from the field.


toBitString

public java.lang.String toBitString()
Render the bit field as a string of 1s and 0s. The length of the string is the length of the bit field, and the first character represents bit 0, with successive characters representing successive bits from the field.


toHexString

public java.lang.String toHexString()
Render the bit field as a string of hexadecimal digits, each representing four bits (one nybble) from the field. The first character represents bits 0 through 3, and successive characters representing successive nybbles from the field. Within each nybble the first bit is high, so that the fourth bit in the nybble is the lowest bit. The length of the returned string is a quarter of the length of the bit field, rounded up to the next whole number, and the last digit will thus not represent a whole four bits if the length of the bit field is not a multiple of four.


equals

public boolean equals(java.lang.Object obj)
Return true if the supplied argument is a bit string equal to this bit string, ie having the same number of bits and all matching bit settings.

Overrides:
equals in class java.lang.Object