comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: Base64-Encoding
Date: Tue, 16 Oct 2007 06:42:52 -0400
Date: 2007-10-16T06:42:52-04:00	[thread overview]
Message-ID: <uzlyjs5lf.fsf@stephe-leake.org> (raw)
In-Reply-To: 20071015183919.79798fe6@cube.tz.axivion.com

Stefan Bellon <sbellon@sbellon.de> 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



  reply	other threads:[~2007-10-16 10:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-15 14:12 Base64-Encoding Stefan Bellon
2007-10-15 14:46 ` Base64-Encoding Jacob Sparre Andersen
2007-10-15 14:54   ` Base64-Encoding Stefan Bellon
2007-10-15 15:14     ` Base64-Encoding Jacob Sparre Andersen
2007-10-15 15:37       ` Base64-Encoding Robert A Duff
2007-10-15 15:40     ` Base64-Encoding Jean-Pierre Rosen
2007-10-15 16:39       ` Base64-Encoding Stefan Bellon
2007-10-16 10:42         ` Stephen Leake [this message]
2007-10-17 14:07           ` Base64-Encoding Stefan Bellon
2007-10-17 15:09             ` Base64-Encoding Adam Beneschan
2007-10-17 18:15               ` Base64-Encoding Larry Kilgallen
2007-10-15 18:24 ` Base64-Encoding Adam Beneschan
2007-10-19  2:43 ` Base64-Encoding anon
2007-10-19  4:33   ` Base64-Encoding anon
2007-10-19  7:35     ` Base64-Encoding Jean-Pierre Rosen
2007-10-19  6:59   ` Base64-Encoding Stefan Bellon
2007-10-19 19:40     ` Base64-Encoding anon
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox