>       As per the standard X.690,
> 8.3.3 : The content octets shall be a two's complement binary number equal
> to the integer
>          Value.
>
>       But in the Book ASN.1 Communication between heterogenous Systems, it is
> given as
>       "binary encoding of the integer if it is positive, or its two's-complement
> if it is
>       negative."
>
>       I would like to know whether an integer value is encoded in 2's Complement
> irrespective of whether it is positive or negative .
>       Or is it that only negative integer values are encoded in 2's complement.

The problem lies in whether we use the term "two's complement" to mean
a) a method of representing integers, or
b) a function.

That is, one can correctly say that the representation of +1 in two's
complement (using one octet) is 01, yet also correctly say that the two's
complement of 01 is FF.

Two's complement, as a method, defines a system that encompasses both
negative and positive numbers (and, of course, 0). It's not that there are
two rules, one for positive and another for negative. Two's complement, as
a function, defines how you turn one bit pattern into another. The
standard uses the term as a method; the book uses the term as a function.

The standard contains a note (see section 8.3.3 in the 1998 document)
seeking to render the point crystal clear. Unfortunately, sometimes the
precise language used within a standard, in practice, simply befuddles the
reader.

In the strictest sense, the standard is more correct than the book, if for
no other reason, simply because it is THE STANDARD, but we must admit
that the book was deliberately written in a looser fashion to serve a
wider audience.

Now, presuming your question was not purely philosophical, the table
below should provide you with enough examples to make sense of the
standard and/or book:

+1    01
-1    FF
+128  0080
-128  80

=====================================================================
Conrad Sigona                         Toll Free      : 1-888-OSS-ASN1
OSS Nokalva                           Voice Mail     : 1-732-302-9669 x400
[EMAIL PROTECTED]                        Fax            : 1-419-831-5035
http://www.oss.com                    My direct line : 1-315-845-1773




Reply via email to