comp.lang.ada
 help / color / mirror / Atom feed
* Converting Binary to Decimal
@ 2001-03-25 21:37 WM
  2001-03-26  4:51 ` Wilhelm Spickermann
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: WM @ 2001-03-25 21:37 UTC (permalink / raw)


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!





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2001-03-29 22:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-25 21:37 Converting Binary to Decimal WM
2001-03-26  4:51 ` Wilhelm Spickermann
2001-03-26 12:36 ` Des Walker
2001-03-26 20:57 ` Phaedrus
2001-03-28  8:15   ` Converting Binary to Decimal - holy war alert Martin Dowie
2001-03-28 18:43     ` Phaedrus
2001-03-29  7:31       ` Martin Dowie
2001-03-29 22:50         ` Robert A Duff

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox