BIT STRING

The ASN.1 BIT STRING type is converted to a C# class that inherits the Asn1BitString run-time class. This base class encapsulates the following two public member variables:

   public int numbits;
   public byte[] mValue;

These describe the bit string to be encoded or decoded.

The following shows the basic mapping from ASN.1 type to C# class definition:

ASN.1 Production:
<name> ::= BIT STRING
Generated C# class:
   public class <name> : Asn1BitString {
   public <name> () :
      base() {
   }
   public <name> (int numbits_, byte[] data) :
      base (numbits_, data) {
   }
   public <name> (bool[] bitValues) :
      base (bitValues) {
   }
   public <name> (string value_) :
      base (value_) {
   }
}

This shows the class generated for a simple BIT STRING assignment. If a tagged or constrained type is specified, specific encode and decode methods will be generated as well.

The constructors generated for this type provide additional options for populating the member variables in the base class. In addition to passing the string using the numbits and data arguments to specify a bit string in native format, the string can be specified as an array of boolean values or as a string. The string form expects the string to be passed in the ASN.1 value notation format for either a binary string (i.e., ‘xxxx’B) or a hexadecimal string (i.e., ‘xxxx’H).

Named Bits

In the ASN.1 standard, it is possible to define an enumerated bit string that specifies named constants for different bit positions. ASN1C provides support for this type of construct by generating symbolic constants that can be used to set, clear, or test these named bits. These symbolic constants are simply the bit names and values in the following general form:

   public readonly static int <name> = <value>;

The base class contains the following methods for using these generated constants:

Set : This method can be used to set a bit in the bit string to be set. There is also an overloaded version that takes a boolean value argument that can be used to set the bit to the given boolean value.

Clear : This method can be used to clear the named bit in the bit string.

Get : This method can be used to test if the named bit is set or clear.

See the Asn1BitString class description in the run-time section for more details on these methods.