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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bffcdbd805329ff8 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-30 00:08:05 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!newsfeed.direct.ca!look.ca!newshub2.rdc1.sfba.home.com!news.home.com!news1.rdc1.sfba.home.com.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Ada and Internet stuff References: X-Newsreader: Tom's custom newsreader Message-ID: Date: Thu, 30 Aug 2001 07:08:04 GMT NNTP-Posting-Host: 24.7.82.199 X-Complaints-To: abuse@home.net X-Trace: news1.rdc1.sfba.home.com 999155284 24.7.82.199 (Thu, 30 Aug 2001 00:08:04 PDT) NNTP-Posting-Date: Thu, 30 Aug 2001 00:08:04 PDT Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: archiver1.google.com comp.lang.ada:12585 Date: 2001-08-30T07:08:04+00:00 List-Id: > >of input and encodes it in 4 output text characters. But the code > >to automagically adjust to Stream_Elements that aren't 8 bits wide > >would, I suspect, be substantally less clear, and rarely used, so > > It only takes about 2 declarations to do this, and the resulting constants can For true generality, the obvious is something along the lines: Finding the GCD of 24 and any number from 1 .. 64 takes at most 5 iterations. So a1 : constant := 24; b1 : constant := Stream_Element'size; ... a5 := b5 := will give the GCD. LCM : constant := 24*Stream_Element'size/GCD; -- LCM is the least common multiple of 24 bits and Stream_Element'size type Encoded_24 is record a,b,c,d:Six_Bits; end record; for Encoding_Block use record a at 0 range 0 .. 5; b at 0 range 6 .. 11; c at 0 range 12 .. 17; d at 0 range 18 .. 23; end record; for Encoding_Block'size use 24; type Encodable_Group is array(1 .. LCM/24) of Encodable_Block; for Encodable_Group'size use LCM; subtype To_Encode is Stream_Element_Array(1 .. LCM/Stream_Element'size); for To_Encode'size use LCM; function SE_To_Group is new Ada.Unchecked_Conversion (Source => To_Encode, Target => Encodable_Group); The_Group : Encodable_Group; Then encoding proceeds in chunks by collecting a slice, si := Source'first; while si <= Source'last loop The_Group := SE_To_Group(Source(si .. Stream_Element_Offset'min( Source'last, si+To_Encode'length-1)) & end_case_padding); for i in Encodable_Group'range loop Emit(Translation_Character(The_Group(i).a); exit when this is the last actual datum excluding padding; Emit(Translation_Character(The_Group(i).b); exit when this is the last actual datum excluding padding; Emit(Translation_Character(The_Group(i).c); exit when this is the last actual datum excluding padding; Emit(Translation_Character(The_Group(i).d); exit when this is the last actual datum excluding padding; end loop; si := si+To_Encode'length; end loop; That's large and obscure. Is there a better way?