comp.lang.ada
 help / color / mirror / Atom feed
From: Stefan Bellon <sbellon@sbellon.de>
Subject: Re: Base64-Encoding
Date: Mon, 15 Oct 2007 18:39:19 +0200
Date: 2007-10-15T18:39:19+02:00	[thread overview]
Message-ID: <20071015183919.79798fe6@cube.tz.axivion.com> (raw)
In-Reply-To: bl10ff.aok.ln@hunter.axlog.fr

On Mon, 15 Oct, Jean-Pierre Rosen wrote:
> Stefan Bellon a écrit :

> > I hoped for this as well, but it looks like the attribute Bit_Order
> > is only defined for record types. This is what 13.5.3 says and
> > indeed GNAT refuses to accept a 'Bit_Order on Six_Bits or the array
> > thereof.
> 
> Bit_Order is about bit numbering, it has nothing to do with endianness

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

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.

Then iterate over the Six_Bits' array and use the values (which are mod
2**6) to index the Base64_Chars array and build the result buffer.

However, when the 1st Byte contains the value Character'Pos('0') = 48,
I hoped that the first Six_Bits element in the array contained the
first 6 bits and thus has a value of 48 / 4 = 12. But this is not the
case. It has the value 48 as well.

In the case of Character'Pos('A') = 65, the usual bit value is
2#01000001#, so I had assumed the first Six_Bits element had the value
16 and the second Six_Bits element had the value 16 as well (assuming
0-padding).

          Data(1)
           __65__
          /      \
          010000010000...
          010000010000
          \____/\____/
            16    16
          B64(1) B64(2)

But in fact, both Six_Bits elements have the value 1. The fact, that I
get 1 in both cases, leads me to the conclusion, that the
Six_Bits_Array overlays differently:

              Data(1)
               __65__
              /      \
       ...000001000001
          000001000001
          \____/\____/
             1     1
          B64(2) B64(1)

When I test this now with two consecutive bytes, I had expected to get:

          Data(1) Data(2)
           _129__  _126__
          /      \/      \
          100000010111111000...
          \____/\____/\____/
            32    23    56
         B64(1) B64(2) B64(3)

But what I am seeing is this:

B64(1..3) = (1, 58, 7) = (2#000001#, 2#111010#, 2#000111#)

But this only makes sense, if the bits are in complete reverse order:

             7     58      1
          000111 111010 000001

Therefore I assume that when overlaying the array of 6-bit elements
over an array of 8-bit elements, I have to specify some kind of bit
ordering, which however is not possible with 'Bit_Order.

What am I missing here?

-- 
Stefan Bellon



  reply	other threads:[~2007-10-15 16:39 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       ` Stefan Bellon [this message]
2007-10-16 10:42         ` Base64-Encoding Stephen Leake
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