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,74e13f9928bee620 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-03 10:56:14 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!newsfeed.r-kom.de!news-nue1.dfn.de!news-ber1.dfn.de!news.uni-hamburg.de!cs.tu-berlin.de!uni-duisburg.de!not-for-mail From: Georg Bauhaus Newsgroups: comp.lang.ada Subject: Re: Base 12 Integer IO Date: Mon, 3 Feb 2003 18:56:14 +0000 (UTC) Organization: GMUGHDU Message-ID: References: NNTP-Posting-Host: l1-hrz.uni-duisburg.de X-Trace: a1-hrz.uni-duisburg.de 1044298574 12961 134.91.1.34 (3 Feb 2003 18:56:14 GMT) X-Complaints-To: usenet@news.uni-duisburg.de NNTP-Posting-Date: Mon, 3 Feb 2003 18:56:14 +0000 (UTC) User-Agent: tin/1.5.8-20010221 ("Blue Water") (UNIX) (HP-UX/B.11.00 (9000/800)) Xref: archiver1.google.com comp.lang.ada:33740 Date: 2003-02-03T18:56:14+00:00 List-Id: Paolo Argenton wrote: : : I would like to do base 12 Integer IO; The following certainly has some flaws, but it might, I hope, provide something with which you can start. The package `dozens' allows a conversion to plain base 12 number strings, 0-padding is added in a test routine that follows: with Ada.Text_IO; use Ada.TExt_IO; with Ada.strings.fixed; use Ada.strings.fixed; with dozens; use dozens; procedure dtest is max_digits: constant := 4; -- duodecimal digits needed, adjust accordingly, affects padding function add_padding(nrep: String) return String; -- adds padding to number string `nrep` function add_padding(nrep: String) return String is offset: constant Integer := Boolean'pos(nrep(nrep'first) = '-'); -- nrep represents a negative number iff 1 begin return (offset * '-') & tail(nrep(nrep'first + offset.. nrep'last), max_digits, pad => '0'); end add_padding; begin for d in Base_12_int(-12)..12 loop put_line(add_padding(dozens.to_string(d)) & " for decimal " & Base_12_int'image(d)); end loop; end dtest; package dozens is type Base_12_int is range -(12**10).. 12**10 - 1; function to_string(n: Base_12_int) return String; end dozens; with Ada.text_IO; with Ada.strings.fixed; use Ada; package body dozens is package B12_IO is new Text_IO.Integer_IO(num => Base_12_int); -- see body statements below for default settings --------------- -- to_string -- --------------- -- we know the prefix "-12#" has a length of 4 characters, -- and there is "#" in the end function to_string (n: Base_12_int) return String is use B12_IO, strings.fixed; result: string (1..default_width + 5); -- enough given a base >= 10 begin put(result, n); declare bare: constant String := trim(result, strings.left); begin if n < 0 then return '-' & bare(5.. bare'last-1); else return bare(4.. bare'last-1); end if; end; end to_string; begin B12_IO.default_base := 12; end dozens;