[英]Encoding and decoding ASN.1 REAL with BER
對不起,我的英語不好。 我在十進制系統中有一個數字: 0.15625 。
(這是示例) http://www.strozhevsky.com/free_docs/asn1_in_simple_words.pdf (第5頁)
根據BER ASN.1的規則-編碼為八進制: 09 03 90 FE 0A (這是正確的決定)
http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf-Standart ASN.1(8.5-REAL)
1個字節:
(8-7) Class - Universal - 00
(6) P/C - Primitive - 0
(5-1) Tag Number - 01001(REAL)
總計:00001001(2)= 09(16) (正確)
2個字節:
(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?
總數:1?010011-不等於03為什么? (不正確)
90是什么? 叫八位位組? 如何找到它? 這本書沒有說,或者我根本聽不懂。
在FE編碼數字-2(指數)中,如何翻譯FE而不是254和-2? 也許它包含有關字節的信息: 90 ?
感謝您的收聽。
在“第1章。ASN.1編碼的通用規則”部分中,聲明了編碼包含三個部分:
長度塊指定值塊的長度。
0.15625作為八位字節09 03 80 FB 05
的編碼分解如下:
09 - information block (1 octet)
03 - length block (1 octet)
80 FB 05 - value block (3 octets)
值塊本身包括三個部分:一個信息八位字節,一個用於指數的塊和一個用於尾數的塊。 在這種情況下,尾數為M = 5(以2為底的101),指數為E = -5。 因此,值塊為:
80 - information octet
FB - the exponent block (FB = -5)
05 - the mantissa block (5)
信息八位字節指定各種信息,包括:
要回答有關將FE解釋為-2的問題,這是2s補數算法中表示負數的方式(更多信息) 。 對於單字節數字,我們有:
FF -> -1
FE -> -2
FD -> -3
...
80 -> -128
7F -> +127
7E -> +126
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.