From: Francis Cianfrocca Date: 2006-12-09T21:20:21+09:00 Subject: Re: Am I missing something about BER-compressed integer? ------=_Part_10038_19147161.1165666819063 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 12/9/06, Edwin Fine wrote: > > Ruby uses BER as specified by Perl. Excerpt from the perlpacktut page: > > The pack code w has been added to support a portable binary data > encoding scheme that goes way beyond simple integers. A BER (Binary > Encoded Representation) compressed unsigned integer stores base 128 > digits, most significant digit first, with as few digits as possible. > Bit eight (the high bit) is set on each byte except the last. There is > no size limit to BER encoding, but Perl won't go to extremes. Thanks for this info. BER is not specified by Perl, of course, but rather by the ITU. The only normative language I've found on the "BER-compressed integer" encoding (that's the language appearing in Ruby pack.c) is in ITU/X.690, graf 8.19.2: "Each subidentifier is represented as a series of (one or more) octets. Bit 8 of each octet indicates whether it is the last in the series: bit 8 of the last octet is zero; bit 8 of each preceding octet is one. Bits 7 to 1 of the octets in the series collectively encode the subidentifier. Conceptually, these groups of bits are concatenated to form an unsigned binary number whose most significant bit is bit 7 of the first octet and whose least significant bit is bit 1 of the last octet. The subidentifier shall be encoded in the fewest possible octets, that is, the leading octet of the subidentifier shall not have the value 80(16)." But the "normal" BER encoding for integers is specified in graf 8.3.3 of the same document: "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." Array#pack doesn't support this encoding as far as I know (I ended up writing it by hand in the Net::BER module). ------=_Part_10038_19147161.1165666819063--