From: "WM" <wwminirl@hotmail.com>
Subject: Converting Binary to Decimal
Date: Sun, 25 Mar 2001 22:37:56 +0100
Date: 2001-03-25T22:37:56+01:00 [thread overview]
Message-ID: <99lofd$19j37@tech.port.ac.uk> (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!
next reply other threads:[~2001-03-25 21:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-03-25 21:37 WM [this message]
2001-03-26 4:51 ` Converting Binary to Decimal 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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox