directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jérôme Baumgarten (JIRA) <directory-...@incubator.apache.org>
Subject [jira] Commented: (DIRSNICKERS-108) Wrong int encoding in Value
Date Fri, 23 Sep 2005 14:49:32 GMT
    [ http://issues.apache.org/jira/browse/DIRSNICKERS-108?page=comments#action_12330279 ]


Jérôme Baumgarten commented on DIRSNICKERS-108:
-----------------------------------------------

Regarding decoding of encoded int, there's an easy and straightforward way :

static public int decode(byte[] bytes) {
  return new BigInteger(bytes).intValue();
}

and another way :

  static public int decode(byte[] bytes) {
    int value = 0;
    if ((bytes[0] & 0x80) != 0) {
      // negative value
      value = -1; // 0xFFFFFFFF
    }

    value = (value << 8) | bytes[0];

    for (byte i = 1 ; i < bytes.length ; i++) {
      // The following doesn't work because of the numeric promotion of bytes[i]
      // as explained in section 5.6.2 Binary Numeric Promotion of the
      // Java Language SpecificationThird Edition
      // http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#170983
      // value = (value << 8) | bytes[i];
      value = (value << 8) | (bytes[i] & 0x00FF);
    }
    return value;
  }

Jérôme

> Wrong int encoding in Value
> ---------------------------
>
>          Key: DIRSNICKERS-108
>          URL: http://issues.apache.org/jira/browse/DIRSNICKERS-108
>      Project: Directory ASN1
>         Type: Bug
>   Components: BER Runtime
>     Reporter: Jérôme Baumgarten
>     Assignee: Emmanuel Lecharny
>     Priority: Blocker
>  Attachments: Value.patch
>
> Hi,
> Encoding is buggy for int value in the org.apache.asn1new.ber.tlv.Value class. The affected
methods are :
> * public static int getNbBytes( int value )
> * public static byte[] getBytes( int value )
> Regards,
> Jérôme

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


Mime
View raw message