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,1829baf3f3969656 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-03-26 12:58:12 PST Path: supernews.google.com!sn-xit-03!supernews.com!news-out.usenetserver.com!news-out-sjo.usenetserver.com!feed2.onemain.com!feed1.onemain.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: <99lofd$19j37@tech.port.ac.uk> Subject: Re: Converting Binary to Decimal 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: Mon, 26 Mar 2001 20:57:55 GMT NNTP-Posting-Host: 209.178.103.28 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 985640275 209.178.103.28 (Mon, 26 Mar 2001 12:57:55 PST) NNTP-Posting-Date: Mon, 26 Mar 2001 12:57:55 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: supernews.google.com comp.lang.ada:6076 Date: 2001-03-26T20:57:55+00:00 List-Id: Simplify, simplify! If you're going to put together a piece of code and you're a beginner in the language, try stepping into the problem. First step, get the input. Test to make sure you're getting it correctly. Use meaningful names, please! For instance, "a_bin_num" implies that it's a variable, which it isn't. It's a type, so try calling it "a_bin_num_type", that should help to eliminate some confusion. Also, your "Binary_Number" (This might be a good time to think about an uppercase/lowercase convention.) isn't a binary number, it's a binary digit. Be precise, it pays off when you start writing longer pieces of code. Second step, conversion. If you've got good data in your array, converting it to the output type should be a piece of cake. Third (and final) step, output. Ada makes this easy, but still it's useful to keep the step alive. For instance, if you had accidentally set the following Ada.Integer_Text_Io.Default_Base := 2; somewhere in your code, you'd realize that everything else was correct and so the error HAD to be in the output format. (And no, you can't just set the Default_Base to 2, and use it to read the number for you. Shame, isn't it?) Following the old Input-Process-Output style will get you through a LOT of programming courses. Phaedrus "WM" wrote in message news:99lofd$19j37@tech.port.ac.uk... > I am writing a program like this: > ----------------------------------------------------------------------- > with Ada.Text_Io,Ada.Integer_Text_Io; > use Ada.Text_Io,Ada.Integer_Text_Io; > > procedure Bin_2_Dec_Test is > > answer : integer; > subtype Binary_Number is Integer range 0..1; --define data type > type a_bin_num is array(1..8) of Binary_Number; --define array type > > bin : Binary_Number; > > function Bin_To_Dec(bin:Binary_Number) return Integer is > Answer : Integer :=0; > begin > for J in reverse 1..8 loop > Answer := Answer + a_bin_num(Bin(J))*(2**(J-1)); > end loop; > return Answer; > end Bin_To_Dec; > > begin > Put_Line("input binary number please: "); > for num in 1..8 loop > Get(a_bin_num(num)); > end loop; > Put_Line("decimal is: "); > Put(Answer(a_bin_num)); > end Bin_2_Dec_Test; > ------------------------------------------------------------------- > It gives me a lot of errors... really don't know what's wrong... > Please give some hints, thanks! > > >