comp.lang.ada
 help / color / mirror / Atom feed
From: "Marin David Condic" <marin.condic.auntie.spam@pacemicro.com>
Subject: Re: Binary value
Date: Mon, 2 Apr 2001 10:33:16 -0400
Date: 2001-04-02T14:33:17+00:00	[thread overview]
Message-ID: <9aa2jd$e4t$1@nh.pace.co.uk> (raw)
In-Reply-To: 2GLx6.16115$aP5.1507862@newsread2.prod.itd.earthlink.net

Here's a trick that might not have occurred to you: You want to set a
"default base" and let the user type in a number like that without having to
put in all the dingleberries around the digits. (Digits in this case is a
misnomer. What is the word I want?)

Prefix    : constant String := "16#" ;
Suffix    : constant String := "#" ;
....
Text_IO.Get_Line (Some_String, Last) ;
....
Integer_Text_IO.Get (
    From => Prefix & Some_String (1..Last) & Suffix,
    Item => Some_Integer,
    Last => Last) ;
....

Naturally, you can do some setup with the prefix & suffix strings to make
them selectable by the user at runtime. In the end, you probably want to
read numbers in as strings anyway because you will want to create more
forgiving editing than you customarily get immediately from Ada. (Quite
often a response can be a number of things besides a number. Picture in your
mind: "Enter the number or type 'Exit' to go back or 'Quit' to
terminate...")

Just another way of removing the epidermis from the household feline.

MDC

--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/


"Phaedrus" <phaedrusalt@hotmail.com> wrote in message
news:2GLx6.16115$aP5.1507862@newsread2.prod.itd.earthlink.net...
> I've often thought that the "default base" in text_io should allow you to
set
> the default INPUT base, too, so that users of it could just specify that
they
> wanted the user to be able to plug in a number in a certain base without
> using the base and pound signs.  Unfortunately, it doesn't work that way.
>
> > To convert an inputted binary number to base ten, simply enter it as a
> > binary number.  If the program says "Get(N)", you can legally provide
> > 38, 2#1001#, 16#DEADBEEF#, etc.
>
> True, and it works great, except that the base and pound signs are
> sort of a pain.  If you were going to enter, say, 30 or 40 binary numbers,
> each consisting of 8 or more digits, orif you're writing a utility
> to be used by less-than-advanced users, who might balk at writing the
> base and the pound signs, or to convert binary data that is input as an
> ASCII stream by an external device.... I can think of many situations
where the
> user might object to typing in the base and pound signs.  (For instance,
> what if the calculator in windows required you to put the base and pounds
> around a number?  Who'd use it?)
> In that case, you're pretty much left with using a loop to get the number.
And
> once you've got it, it's kind of cool to be able to convert it without any
> calculation.
> I really love the look on people's faces when they ask to see the
algorithm
> for verification!  "There isn't one" isn't an answer they're used to
hearing.
>






  parent reply	other threads:[~2001-04-02 14:33 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-30 16:10 Binary value Bob Gratton
2001-03-30 16:54 ` Marin David Condic
2001-03-30 17:16   ` Bob Gratton
2001-03-30 17:41     ` Marin David Condic
2001-03-30 18:20       ` Bob Gratton
2001-03-30 19:58         ` Marin David Condic
2001-03-30 18:21     ` chris.danx
2001-03-30 20:03       ` Marin David Condic
2001-03-30 20:32       ` Smark
2001-03-30 20:45         ` Smark
2001-03-30 21:19           ` chris.danx
2001-03-31  5:23       ` Phaedrus
     [not found]         ` <3AC5C72F.8108A613@earthlink.net>
2001-04-01 19:52           ` Phaedrus
2001-04-01 22:04             ` Robert A Duff
2001-04-01 22:35               ` David C. Hoos, Sr.
2001-04-02 12:49               ` Marc A. Criley
2001-04-02 13:33             ` chris.danx
2001-04-02 14:33             ` Marin David Condic [this message]
2001-04-02 16:43       ` Jeffrey Carter
2001-04-02 17:36         ` chris.danx
2001-04-02 18:03           ` Robert A Duff
2001-04-02 17:54         ` Robert A Duff
2001-03-30 17:03 ` Larry Hazel
replies disabled

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