[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Negative Integers & ASN.1



Title: Re: Negative Integers & ASN.1
there is no specific primitive type for a negative integer. two's compliment encoding is used to represent either a positive, zero, or negative value.

from the encoding rules

8.3 Encoding of an integer value

8.3.1
The encoding of an integer value shall be primitive. The contents octets shall consist of one or more octets.

8.3.2 If the contents octets of an integer value encoding consist of more than one octet, then the bits of the first
octet and bit 8 of the second octet
a) shall not all be ones; and
b) shall not all be zero.
NOTE - These rules ensure that an integer value is always encoded in the smallest possible number of octets.

8.3.3 The contents octets shall be a two's complement binary number equal to the integer value, and consisting of bits 8 to 1 of the first octet, followed by bits 8 to 1 of the second octet, followed by bits 8 to 1 of each octet in turn up to and including the last octet of the contents octets.

NOTE - The value of a two' s complement binary number is derived by numbering the bits in the contents octets, starting with bit 1 of the last octet as bit zero and ending the numbering with bit 8 of the first octet. Each bit is assigned a numerical value of 2 N , where N is its position in the above numbering sequence. The value of the two' s complement binary number is obtained by summing the numerical values assigned to each bit for those bits which are set to one, excluding bit 8 of the first octet, and then reducing this value by the numerical value assigned to bit 8 of the first octet if that bit is set to one.

i assume you must be doing asn.1 encoding by hand; the tools out there handle this issue.

if your question was really about how to constrain the value of a type to be negative, there is notation to do that also

   hoyt


At 9:14 PM -0700 4/25/00, chandrasekaran natarajan wrote:
hello,

Thanks Mr.Peter Gutmann and Aram Perez for helping
me out test my BER/DER Encoding..

I have another doubt....Is there a standard Tag for
Negative Numbers in ASN.1 and  in general can
some one help me out on encoding Negative Integers.

Thanks

Chandar



Send FREE April Fool's Greetings to your friends!
http://www.whowhere.lycos.com/redirects/American_Greetings.rdct