From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e710f7d3f890e76b X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!out03a.usenetserver.com!news.usenetserver.com!in01.usenetserver.com!news.usenetserver.com!in03.usenetserver.com!news.usenetserver.com!pc03.usenetserver.com!news.flashnewsgroups.com-b7.4zTQh5tI3A!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Base64-Encoding References: <20071015161229.3f439230@cube.tz.axivion.com> <20071015165435.0eef160d@cube.tz.axivion.com> <20071015183919.79798fe6@cube.tz.axivion.com> From: Stephen Leake Date: Tue, 16 Oct 2007 06:42:52 -0400 Message-ID: User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/22.1 (windows-nt) Cancel-Lock: sha1:hgnXVHSq6t+PiXO3Ob10n0rZqjU= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@flashnewsgroups.com Organization: FlashNewsgroups.com X-Trace: d5907471495a6e05e48ed30700 Xref: g2news2.google.com comp.lang.ada:2462 Date: 2007-10-16T06:42:52-04:00 List-Id: Stefan Bellon writes: > Ok, bad wording on my part. Let my try to explain what I mean. > > The German Wikipedia page for Base64 has a nice coloured illustration: > http://de.wikipedia.org/wiki/Base64 In English: http://en.wikipedia.org/wiki/Base64 Not quite the same illustration, but the same idea. > My basic idea is to define an array of Six_Bits and "overlay" this at > the same address as the String with the usual 8-bit Character encoding. I think Adam is correct that this is non-portable. The GNAT Ada compiler has special code for each case of packed arrays. For Six_Bits_Array, see the package System.Pack_06 (in file s-pack06.adb). It defines: for Cluster use record E0 at 0 range 0 * Bits .. 0 * Bits + Bits - 1; E1 at 0 range 1 * Bits .. 1 * Bits + Bits - 1; E2 at 0 range 2 * Bits .. 2 * Bits + Bits - 1; E3 at 0 range 3 * Bits .. 3 * Bits + Bits - 1; E4 at 0 range 4 * Bits .. 4 * Bits + Bits - 1; E5 at 0 range 5 * Bits .. 5 * Bits + Bits - 1; E6 at 0 range 6 * Bits .. 6 * Bits + Bits - 1; E7 at 0 range 7 * Bits .. 7 * Bits + Bits - 1; end record; where Bits is 6. There is no Bit_Order pragma on this, so it is in native bit order; apparently little-endian in your case (x86). So Base64_Data (0) has bits 0 .. 5 of Data (0), Base64_Data (1) has bits 6, 7 of Data (0) and bits 0 .. 3 of Data (1), etc. In effect, the bytes in Data are reversed in groups of 6. Not easy to draw :(. AdaCore does not implement Bit_Order for machine sizes greater than 1 (last I checked; a couple years ago). If they did, and applied bit_order to this record, it would be endian-independent, and work the way you expect. It would also break any current code, so they probably never will. But you could at least code it yourself in a cleaner endian-independent way. So ask them to! -- -- Stephe