comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@bix.com
Subject: Re: Newbie question : types , representation
Date: 1999/08/27
Date: 1999-08-27T00:00:00+00:00	[thread overview]
Message-ID: <5oAx3.5359$W5.510061@typhoon-sf.snfc21.pbi.net> (raw)
In-Reply-To: 37C621F3.C6C0DC3A@acenet.com.au

> In base64 decoding , each ASCII character must be translated to 6 'bit'.
> 4 characters translate then to 3 bytes. The problem and algorithms are
> trivial. In C I could do it within 5 minutes.

Given modern RAM sizes, how about the initally mentioned table lookup
   type Base64 is range 0 .. 63;
   type Base64_String is array(integer range <>) of Base64;
   subtype Base64_Quad is Base64_String(1 .. 4);

   type Byte is range 0 .. 255;
   type Byte_String is array(integer range <>) of Byte;
   subtype Byte_Triple is Byte_String(1 .. 3);

   To_Base64 : array(Byte, Byte, Byte) of Base64_Quad;
   From_Base64 : array(Base64, Base64, Base64, Base64) of Byte_Triple;
   -- initialize the arrays once, at start time

   -- timing test
   data: Base64_String(1 .. 200);
   result : Byte_String(1 .. 150);
   si,di : positive;
begin
  for i in 1 .. 100_000 loop
    si := 1;
    di := 1;
    for j in 1 .. data'length/4 loop
      result(di .. di+2) := From_Base64(Data(si), Data(si+1),
                                        Data(si+2), Data(si+3));
      di := di+3;
      si := si+4;
    end loop;
  end loop;

On my P200, this sort of thing executes at a rate of about 6 Base64
characters, or 4 Byte's, converted each microsecond.  Using a
modern fast CPU you would approach being I/O bound.




  parent reply	other threads:[~1999-08-27  0:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-08-22  0:00 Newbie question : types , representation Jos De Laender
1999-08-22  0:00 ` Wilhelm Spickermann
1999-08-23  0:00   ` Martin C. Carlisle
1999-08-23  0:00   ` Simon Wright
1999-08-22  0:00 ` Robert Dewar
1999-08-23  0:00   ` Wolfgang Jeltsch
1999-08-24  0:00     ` tmoran
1999-08-24  0:00   ` jdla
1999-08-24  0:00     ` Matthew Heaney
1999-08-24  0:00       ` Jos De Laender
1999-08-24  0:00         ` Brian Rogoff
1999-08-25  0:00           ` Jos De Laender
1999-08-22  0:00 ` Martin Dowie
     [not found] ` <37C621F3.C6C0DC3A@acenet.com.au>
1999-08-27  0:00   ` tmoran [this message]
1999-08-27  0:00     ` Florian Weimer
1999-08-27  0:00   ` David C. Hoos, Sr.
replies disabled

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