简体   繁体   中英

Encoding and decoding ASN.1 REAL with BER

Excuse me for my bad english. I have a number in the decimal system: 0.15625 .

(This is example) http://www.strozhevsky.com/free_docs/asn1_in_simple_words.pdf (Page 5)

By the rule of BER ASN.1 - Encoded in octal: 09 03 90 FE 0A (This is the right decision)

http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf - Standart ASN.1(8.5 - REAL)

1 byte:

(8-7) Class - Universal - 00 
(6) P/C - Primitive - 0
(5-1) Tag Number - 01001(REAL)

TOTAL: 00001001(2) = 09(16) (Correct)

2 byte:

     (8) binary encoding - 1
      _____________________
     (7) When binary encoding is used (bit 8 = 1), then if the mantissa M is 
         non-zero, it shall be represented by a sign S, a positive integer value N 
         and a binary scaling factor F, such that:
            M = S × N × 2F
         Bit 7 of the first contents octets shall be 1 if S is –1 and 0 otherwise. 
         What I would have bit 7?
        _____________________
     (6-5) base 8 - 01
       _______________________
     (3-4) Bits 4 to 3 of the first contents octet shall encode the value of
     the binary scaling factor F as an unsigned binary
     integer. I don't have scaling factor. - 00
      _____________________
     (2-1) 8.5.6.4 Bits 2 to 1 of the first contents octet shall encode 
     the format of the exponent as follows: I do not know how to determine 
     what my value will be here. (Poor understand English). I think 11?

Total: 1?010011 - NOT EQUAL 03 Why? (Not correct)

What does the 90 ? Call octet? How to find it? The book does not say, or I simply do not understand.

In FE coded number -2(Exponent), how do I translate FE , not to get 254, and -2? Perhaps it contains information about the byte: 90 ?

Thank you for listening.

In the section "Chapter 1. Common rules for ASN.1 encoding" it states that an encoding has three sections:

  1. an information block
  2. a length block
  3. a value block

The length block specifies the length of the value block.

The encoding of 0.15625 as the octets 09 03 80 FB 05 breaks down like this:

09       - information block (1 octet)
03       - length block (1 octet)
80 FB 05 - value block (3 octets)

The value block itself consists of three sections: an information octet, a block for the exponent and a block for the mantissa. In this case the mantissa is M = 5 (101 in base 2) and the exponent is E = -5. Therefore the value block is:

80       - information octet
FB       - the exponent block (FB = -5)
05       - the mantissa block (5)

The information octet specifies various pieces of information including:

  • that we are encoding a real number
  • we are using in base 2, and
  • the number is non-negative (>= 0)

To answer your question about FE being interpreted as -2, this is how negative numbers are represented in 2s-complement arithmetic (more info) . For single octet numbers we have:

FF   ->  -1
FE   ->  -2
FD   ->  -3
...
80   ->  -128
7F   ->  +127
7E   ->  +126

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM