comp.lang.ada
 help / color / mirror / Atom feed
From: Des Walker <des.walker@amsjv.com>
Subject: Re: Converting Binary to Decimal
Date: Mon, 26 Mar 2001 13:36:29 +0100
Date: 2001-03-26T13:36:29+01:00	[thread overview]
Message-ID: <3ABF37CD.3A01C20B@amsjv.com> (raw)
In-Reply-To: 99lofd$19j37@tech.port.ac.uk


Hi,

this is not really an answer to your question, please disregard if it is
not relevant.

Have you considered reading your binary number as a string and using
predefined attributes to convert it. e.g.

with Ada.Text_Io; use Ada.Text_Io;

procedure Convert_Test is
  Value_Str : String(1 .. 8);
  Last : Natural;
  Value_Int : Integer;
begin
  Put_Line("input binary number please: ");
  Get_Line(Value_Str, Last);
  Value_Int := Integer'Value("2#" & Value_Str(1 .. Last) & '#');
  Put_Line("Decimal is" & Integer'Image(Value_Int));
end Convert_Test;

Admittedly if the user typed a bad digit, this version would produce a
Constraint Error on the conversion, whereas yours would produce an error
on the Get call.

	Des Walker
	Alenia-Marconi Systems



  parent reply	other threads:[~2001-03-26 12:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-25 21:37 Converting Binary to Decimal WM
2001-03-26  4:51 ` Wilhelm Spickermann
2001-03-26 12:36 ` Des Walker [this message]
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