Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

binary decimals

2 views
Skip to first unread message

Michael Crone

unread,
Aug 1, 1998, 3:00:00 AM8/1/98
to
Hi,
I need to write a program which takes from the keyboard a binary
floating point number.. eg: 111.0111 would be valid, but 111.23 wouldn't

be.. Anyone know a good way to take this number (checking it is valid)
and convert it to decimal..

Thanks

Michael
cr...@it.net.au


Ing. Franz Glaser

unread,
Aug 1, 1998, 3:00:00 AM8/1/98
to

Look for "ValRadix" in the numerics chapter of the
TP-links site:
http://www.geocities.com/SiliconValley/2926/tp.html

Franz Glaser

Michael Crone

unread,
Aug 1, 1998, 3:00:00 AM8/1/98
to
Ok, thanks for that..

I had a look at it, and since I'm quite new to pascal, it is a bit confusing
to me about how exactly this program works.. Can you make it a bit clearer for
me?

Ing. Franz Glaser

unread,
Aug 1, 1998, 3:00:00 AM8/1/98
to Michael Crone

Sorry, I thought that I had written it very clearly...

The procedure is used as a flexible replacement for the
TP - built in VAL(S,R,E) procedure. The flexibility is:
it can be used for any number base between 2 (binary)
and 36 (which is seldom used, for some Radix50 tricks only).

The principle is:
Take all chars of the string sequentially from left to
right and convert them to a number, in this case to a
REAL number. There are some special chars, like the leading
hyphen (the MINUS) and the decimal point. Anything else MUST
be a numeric character. Numeric chars in decimal notation are
'0' .. '9', in octal they are '0'..'7' and in binary they
are '0'..'1'.
If you have a radix above 10, eg. for Hex-number notation,
there are not enough ciphers available, so the "standard"
decided to take the characters 'A'..'F' (for Hex).
In any case the principle is the same.

For integer numbers (no decimal point)
For P := 1 to length(S) do
R := R*radix + NumOrd(S[P]);
where numord simply converts the char '0' to the integer 0
etc.

Assume decimal:
R := R*10 + numord(character);
example:
S = '1234';
on start, R=0;
R := R*10+1 --> R = 1
next char
R := R*10+2 --> R = 12
next char
R := R*10+3 --> R = 123
next char
R := R*10+4 --> R = 1234
If a decimal point is encountered, the following
chars do not increase the exponent any more, so that
the number is appended at the right end. But this
is described in the source example in more detail,
using DpL as the "switched" variable.

Franz Glaser

Ing. Franz Glaser

unread,
Aug 1, 1998, 3:00:00 AM8/1/98
to
Ing. Franz Glaser wrote:
>
> Michael Crone wrote:
> >
> > Ok, thanks for that..
> >
> > I had a look at it, and since I'm quite new to pascal, it is a bit confusing
> > to me about how exactly this program works.. Can you make it a bit clearer for
> > me?
> >
> > Ing. Franz Glaser wrote:
> >
> > > Michael Crone wrote:
> > > >
> > > > Hi,
> > > > I need to write a program which takes from the keyboard a binary
> > > > floating point number.. eg: 111.0111 would be valid, but 111.23 wouldn't
> > > >
> > > > be.. Anyone know a good way to take this number (checking it is valid)
> > > > and convert it to decimal..
> > > >
> > > > Thanks Michael
> > >
> > > Look for "ValRadix" in the numerics chapter of the
> > > TP-links site:
> > > http://www.geocities.com/SiliconValley/2926/tp.html
> > >
> > > Franz Glaser
>
> Sorry, I thought that I had written it very clearly...

I appended some comments to the file on the TP-links site,
hope this helps. Press "Reload" on your browser.
Franz Glaser

Nik Synytskyy

unread,
Aug 5, 1998, 3:00:00 AM8/5/98
to

Michael Crone wrote in message <35C2D4AD...@it.net.au>...

>Hi,
> I need to write a program which takes from the keyboard a binary
>floating point number.. eg: 111.0111 would be valid, but 111.23 wouldn't
>
>be.. Anyone know a good way to take this number (checking it is valid)
>and convert it to decimal..
>
To check if the input's valid, us READKEY (from CRT unit) to read the input
character by character, and then discard everything but "1", "0", ".", "-".
The "convert to decimal" part is already described very well by Mr. Glaser

Message has been deleted

Michael Knapp

unread,
Sep 7, 1998, 3:00:00 AM9/7/98
to Joel
www.inprise.com :-))))

Joel schrieb:
>
> does anyonre know where
> i can get a copy of pascal from the internet
>
> email me at joe...@which.net

Frederic GUILLIEN

unread,
Sep 7, 1998, 3:00:00 AM9/7/98
to
Look for at FPK Pascal, or FreePascal, it's a GNU pascal !

Joel a écrit:


>
> does anyonre know where
> i can get a copy of pascal from the internet
>
> email me at joe...@which.net

--
Frederic GUILLIEN

My Web site
http://wwwperso.hol.fr/~fguillei
http://wwwperso.hol.fr/~fguillei/English

Show your support for the Best Windows Development Tool
Join TDAG (The Delphi Advocacy Group)
http://www.tdag.org/

Alexander V. Gaiduk

unread,
Sep 9, 1998, 3:00:00 AM9/9/98
to
>Look for at FPK Pascal, or FreePascal, it's a GNU pascal !
>


and

TMT Pascal
http://www.tmt.com


0 new messages