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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a96b706fab1e8c2c X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-03-30 21:24:06 PST Path: supernews.google.com!sn-xit-03!supernews.com!cyclone2.usenetserver.com!news-out.usenetserver.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!newsmaster1.prod.itd.earthlink.net!newsread2.prod.itd.earthlink.net.POSTED!not-for-mail From: "Phaedrus" Newsgroups: comp.lang.ada References: <9e2x6.568987$JT5.15730002@news20.bellglobal.com> <9a2dnu$sff$1@nh.pace.co.uk> Subject: Re: Binary value X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Message-ID: Date: Sat, 31 Mar 2001 05:23:55 GMT NNTP-Posting-Host: 209.178.103.28 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 986016235 209.178.103.28 (Fri, 30 Mar 2001 21:23:55 PST) NNTP-Posting-Date: Fri, 30 Mar 2001 21:23:55 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: supernews.google.com comp.lang.ada:6283 Date: 2001-03-31T05:23:55+00:00 List-Id: Yeah, I suppose you could do it with an algorithm. But why bother? The machine stores the values in binary, so just take advantage of the fact. Create a packed array of bits at the same location as the integer to be converted. Then just write the array out with a "for" loop. It's not as easy as using the Put routine, but I like the elegance. No muss, no fuss, no bother. By the way, this will also help you in doing the reverse, where Text_io will leave you high and dry. If you want to convert an inputted binary number to base ten, once you've read it in it's no bother at all. And no work, too! Phaedrus "chris.danx" wrote in message news:K84x6.4066$MZ2.743519@news2-win.server.ntlworld.com... > > I see... that answers half of my question. This presumes I wanna convert > > from binary to Integer. But is it possible to "convert" a Integer value to > > binary. > > Suppose you have the value 123 in binary. To convert to binary you need to > follow this algorithm. > > while num /= 0 loop > rem := num mod 2; -- get remainder > num := num - rem; > add rem'image to front* of string; > end loop; > > {I think this is the correct algorithm!} > > You could do it recursively too. > > > Hope this helps, > Chris Campbell > > *if you add rem'image onto the end you'll have to reverse the string after > you finish so it'd be better to add it to the front. I'm assuming you'll > use an unbounded string in the loop and will convert it to a string outside > if you wish. > > >