Thursday, 12 April 2018

ASN.1: BIT STRING

Type: BIT STRING
Description: Used to represent bit arrays. Specific bits can be identified by parenthesized integers and assigned names. It is used to model the binary data of arbitrary length.  The length of the string of bits must be a multiple of four when hexadecimal is used.

Values can be represented in 3 possible forms:
a.   binary - '01'B,
b.   hex - '9'H, and
c.   named - {chess, football}

Examples
Occupation ::=  BIT STRING {
 clerk        (0),
    watchman     (1),
 engineer     (2),
    manager      (3)
}
    
Hobbies ::= BIT STRING {
 chess     (0),
 cricket   (1),
 hockey    (2),
 football  (3),
 others    (4)
}

The numbers in parentheses indicate location in the string of bits. In the above example, first bit is chess, second bit is cricket, third bit is hockey and so on.

Example Schema
Occupation ::=  BIT STRING {
    clerk    (0),
    watchman  (1),
    engineer  (2),
    manager   (3)
}
    
Hobbies ::= BIT STRING {
 chess     (0),
 cricket   (1),
 hockey    (2),
 football  (3),
 others    (4)
}
    
Employee ::= SEQUENCE {
 name VisibleString,
 isPermanentEmployee BOOLEAN,
 id INTEGER,
 age INTEGER (15..60),
 occupation Occupation,
 hobbies Hobbies
}

Sample data for above schema
employee1 Employee ::= {
 name "Rama Krishna",
 isPermanentEmployee FALSE,
 id 12345,
 age 30,
 occupation '010'B,
 hobbies {chess, football}
}

XML encoding of above data
<?xml version="1.0" encoding="UTF-8"?>
<Employee>
  <name>Rama Krishna</name>
  <isPermanentEmployee><false/></isPermanentEmployee>
  <id>12345</id>
  <age>30</age>
  <occupation>01</occupation>
  <hobbies>1001</hobbies>
</Employee>



Previous                                                 Next                                                 Home

No comments:

Post a Comment