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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,22b2c05a8088bbb2 X-Google-Attributes: gid103376,public From: David Shochat Subject: Re: Leading zeros with Int_IO.Put()? Or another package? Date: 1996/11/05 Message-ID: <327FB8A3.745B@itg-sepg.logicon.com>#1/1 X-Deja-AN: 194713110 references: content-type: text/plain; charset=us-ascii organization: Logicon Information Technology Group mime-version: 1.0 reply-to: shochat@itg-sepg.logicon.com newsgroups: comp.lang.ada x-mailer: Mozilla 3.0 (Win95; U) Date: 1996-11-05T00:00:00+00:00 List-Id: J.D. Baldwin wrote: > [snip] > My question: is there a better way to pad out integers with leading > zeros? Whenever I need leading zeros (in any radix), I use what we call here the "Everage Maneuver" (named after fellow Logiconer Amy Everage, who came up with this years ago). Lets say we want to put the nonnegative integer n to a field of k characters with radix r using leading zeros if necessary. So we assert n < r**k. 1. Convert n + r**k to a string. This uses k+1 characters, the 1st of which is '1', representing r**k. 2. Use all but the 1st character from the result of (1). If it makes anyone feel better, it looks like Java (API) doesn't know how to do leading zeros either (but the Everage Maneuver works fine for Java too). -- David