🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.pascal.misc
Article #182

Re: binary decimals

#182
From: Ing. Franz Glaser
Date: Sat, 01 Aug 1998 00:00
72 lines
3815 bytes
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...

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
Technical Details
Message-ID: <35C31CE4.2498080C@eunet.at>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <35C2D4AD.168E0440@it.net.au> <35C2E9B6.3BC47A39@eunet.at> <35C2FB74.48315230@it.net.au>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10c470,bb874037f97d6486
X-Google-Attributes: gid10c470,public
X-Google-Thread: 10261c,bb874037f97d6486
X-Google-Attributes: gid10261c,public
X-Google-Thread: fd1d1,bb874037f97d6486
X-Google-Attributes: gidfd1d1,public
X-Google-Thread: 1006de,bb874037f97d6486
X-Google-Attributes: gid1006de,public
X-Google-Thread: 10a726,bb874037f97d6486
X-Google-Attributes: gid10a726,public
X-Google-Thread: 10263e,bb874037f97d6486
X-Google-Attributes: gid10263e,public
X-Google-Thread: ff90a,bb874037f97d6486
X-Google-Attributes: gidff90a,public
X-Google-Thread: 110467,bb874037f97d6486
X-Google-Attributes: gid110467,public
From: "Ing. Franz Glaser" <meg-glaser@eunet.at>
Subject: Re: binary decimals
Date: 1998/08/01
Message-ID: <35C31CE4.2498080C@eunet.at>
X-Deja-AN: 376962933
Content-Transfer-Encoding: 7bit
References: <35C2D4AD.168E0440@it.net.au> <35C2E9B6.3BC47A39@eunet.at> <35C2FB74.48315230@it.net.au>
To: Michael Crone <crone@it.net.au>
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: abuse@Austria.EU.net
X-Trace: fleetstreet.Austria.EU.net 901979511 13692 193.81.169.142 (1 Aug 1998 13:51:51 GMT)
Organization: MEG Glaser
Mime-Version: 1.0
NNTP-Posting-Date: 1 Aug 1998 13:51:51 GMT
Newsgroups: comp.lang.pascal.misc,de.comp.lang.pascal,de.comp.lang.pascal.misc,fido.ger.pascal,fj.lang.pascal,fr.comp.lang.pascal,it.comp.lang.pascal,maus.lang.tpascal,relcom.comp.lang.pascal