Encoding Examples



next up previous
Next: Comments about BER Up: Basic Encoding Rules Previous: Content

Encoding Examples

 

We give several examples to convey the flavor of BER. ISO 8825 contains a more complex example.

In Subsection gif the type SET was illustrated with the example

  Person   ::=  SET
      {
       name     IA5String,
       age      INTEGER
       female   BOOLEAN
      }.
The BER encoding (in hexadecimal) of the instance "Maggie", 4, TRUE is:
SET    IA5String      M  a  g  g  i  e  INTEGER      4  BOOLEAN      TRUE
31  14   16       06  77 65 71 71 73 69    02    01  04   01      01  FF
where 14, 06, 01, and 01 are lengths of content components. The identifier (I), length (L), and content (C) components are determined as follows: Consider, first the encoding of name "Maggie". In this example, IA5string has class UNIVERSAL (00), type primitive (0), and tag 22 (binary 10110). Its 8-bit identifier component is 00010110, which is 16 in hexadecimal. The ASCII representation of the value "Maggie" is shown above. It consists of 6 octets. Thus, for name "Maggie", we get
   I  L  C
   16 06 77 65 71 71 73 69.
Next, consider age 4. INTEGER has class UNIVERSAL, type primitive, and tag 2. Its value 4, is the single octet 04 in hexadecimal. Thus, for age 4, we get
   I  L  C
   02 01 04.
Next, consider female TRUE. BOOLEAN has class UNIVERSAL, type primitive, and tag 1. The value TRUE is represented by the single octet 11111111, which is FF in hexadecimal. Thus, for female TRUE, we get
   I  L  C
   01 01 FF.
Finally, SET has class UNIVERSAL, type structured (1), and tag 17. Its 8-bit identifier component is 00110001, which is 31 in hexadecimal. The content component consists of the 14 octets obtained by concatenating the above three ILCs.

By examining the encoded version, it becomes apparent why the components in the SET type can be in any order, provided no two components are of the same type. For example, the encoded version of 4, TRUE, "Maggie" would be

  31 14 02 01 04 01 01 FF 16 06 77 65 71 71 73 69.

As an example of encoding the type SET with tagged components, consider the four cases in Figure gif using the instance 180, 180, 0. The first case a) is invalid. In case b), each component has class APPLICATION (01) and type primitive. The integer value 180 has binary representation 10110100 (one octet), which is B4 in hexadecimal. The encoded version of INTEGER 180 is

   I  L  C
   02 01 B4.
The identifier component of [APPLICATION 0] is 01000000, which is 40 in hexadecimal. The encoded version of [APPLICATION 0] 180 INTEGER, then, is
   I  L  C
   40 03 02 01 B4.
Similarly, the encoded version of the occupied and vacant components of seats are 41 03 02 01 B4 and 42 03 02 02 00, respectively. The encoded version of the instance 180, 180, 0 of seats is
   I  L  C
   31 15 40 03 02 01 B4 41 03 02 01 B4 42 03 02 01 00.
Note that the tags removed any ambiguity among ther components of seats, which enables the components to be listed in any order.

The use of IMPLICIT in case c) shortens the encoded string by making it unnecessary to encode the tag for INTEGER. In this case, 40 01 B4 encodes the value 180, and the encoded version of 180, 180, 0 is

   I  L  C
   31 09 40 01 B4 41 01 B4 42 01 00.
Case d) is encoded the same as case b) except that the tags are CONTEXT SENSITIVE (10) rather than APPLICATION (01). In this case, the encoded version of 180, 180, 0 is
   I  L  C
   31 15 80 03 02 02 B4 81 03 02 01 B4 82 03 02 01 00.



next up previous
Next: Comments about BER Up: Basic Encoding Rules Previous: Content



boots cassel
Tue Feb 27 17:07:18 EST 1996