Class BitString

java.lang.Object
org.asnlab.asndt.runtime.value.BitString

public class BitString extends Object
Immutable representation of an ASN.1 BIT STRING, which is equivalent to a byte array except some number of the rightmost bits are ignored. For example, this could be the bit string:
   00010101 11101101 11010xxx

Where the "xxx" represents three bits that should be ignored, and can have any value.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    byte[]
     
    byte
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    BitString(byte[] bytes, byte unusedBits)
    Create a new bit string
    BitString(int length)
    Create a new bit string of a given length
    BitString(org.asnlab.asndt.runtime.type.BitStringType bitStringType)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    boolean
    getBit(int bit)
    Returns the bit at the specified index.
    boolean
    getBit(org.asnlab.asndt.runtime.type.NamedNumber namedBit)
     
    int
    Returns the size, in bits, of this bit string.
    static void
    main(String[] args)
     
    void
    setBit(int bit, boolean value)
    Sets the bit at the specified index.
    void
    setBit(org.asnlab.asndt.runtime.type.NamedNumber namedBit, boolean value)
     
     
    void
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • bytes

      public byte[] bytes
    • unusedBits

      public byte unusedBits
  • Constructor Details

    • BitString

      public BitString(byte[] bytes, byte unusedBits)
      Create a new bit string
      Parameters:
      bytes - The byte array holding the bit string.
      unusedBits - The number of tailing bits that are not used.
      Throws:
      NullPointerException - If bytes is null.
    • BitString

      public BitString(int length)
      Create a new bit string of a given length
      Parameters:
      length - The size of the bit string.
    • BitString

      public BitString(org.asnlab.asndt.runtime.type.BitStringType bitStringType)
  • Method Details

    • trimTailingZeros

      public void trimTailingZeros()
    • clearUnusedBits

      public void clearUnusedBits()
    • getBit

      public boolean getBit(int bit)
      Returns the bit at the specified index.
      Parameters:
      bit - The bit index
      Returns:
      The boolean value of the bit
    • setBit

      public void setBit(int bit, boolean value)
      Sets the bit at the specified index.
      Parameters:
      bit - The bit index
      value - The boolean value of the bit
    • main

      public static void main(String[] args)
    • getBitSize

      public int getBitSize()
      Returns the size, in bits, of this bit string.
      Returns:
      The size of this bit string.
    • getBit

      public boolean getBit(org.asnlab.asndt.runtime.type.NamedNumber namedBit)
    • setBit

      public void setBit(org.asnlab.asndt.runtime.type.NamedNumber namedBit, boolean value)
    • toString

      public String toString()
      Overrides:
      toString in class Object