comp.lang.ada
 help / color / mirror / Atom feed
* help: character to integer
@ 1996-10-01  0:00 Eric Anthony Spear
  1996-10-02  0:00 ` Richard A. O'Keefe
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Eric Anthony Spear @ 1996-10-01  0:00 UTC (permalink / raw)



I've tried to find the answer in the RM, but I haven't had any luck.

Is there a function, either in a package or as an attribute, that can work
like this BASIC function:

i = ASC("X")

That is, the function returns the ASCII value of the given character.

Thanks in advance for any help.





^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: help: character to integer
  1996-10-01  0:00 help: character to integer Eric Anthony Spear
  1996-10-02  0:00 ` Richard A. O'Keefe
@ 1996-10-02  0:00 ` Dave Marshall
  1996-10-07  0:00 ` Paul Tongue
  2 siblings, 0 replies; 16+ messages in thread
From: Dave Marshall @ 1996-10-02  0:00 UTC (permalink / raw)



spear@wam.umd.edu (Eric Anthony Spear) writes:

>I've tried to find the answer in the RM, but I haven't had any luck.

>Is there a function, either in a package or as an attribute, that can work
>like this BASIC function:

>i = ASC("X")

>That is, the function returns the ASCII value of the given character.

>Thanks in advance for any help.

RM83:

3.5.5(6): [Operations of Discrete Types]

T'POS	This attribute is a function.  The parameter X must be a value
of the base type of T.  The result type is the type universal integer.
The result is the position number of the value of the parameter.

So,

My_Integer := Character'Pos('X') -- 16#58#

The corresponding RM95 discussion begins at 3.5.5(2) and even includes
a handy function specification.

-- 
Dave Marshall
dmarshal@netcom.com





^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: help: character to integer
  1996-10-01  0:00 help: character to integer Eric Anthony Spear
@ 1996-10-02  0:00 ` Richard A. O'Keefe
  1996-10-02  0:00   ` George Haddad
  1996-10-02  0:00 ` help: character to integer Dave Marshall
  1996-10-07  0:00 ` Paul Tongue
  2 siblings, 1 reply; 16+ messages in thread
From: Richard A. O'Keefe @ 1996-10-02  0:00 UTC (permalink / raw)



spear@wam.umd.edu (Eric Anthony Spear) writes:

>I've tried to find the answer in the RM, but I haven't had any luck.

It's there.

>Is there a function, either in a package or as an attribute, that can work
>like this BASIC function:

>i = ASC("X")

>That is, the function returns the ASCII value of the given character.

Values of any discrete type can be converted to integers using the 'Pos
attribute and back again using the 'Val attribute.  This was so in Ada 83
and is still so in Ada 95.   You want

	I := Character'Pos('X');

-- 
Australian citizen since 14 August 1996.  *Now* I can vote the xxxs out!
Richard A. O'Keefe; http://www.cs.rmit.edu.au/%7Eok; RMIT Comp.Sci.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: help: character to integer
  1996-10-02  0:00 ` Richard A. O'Keefe
@ 1996-10-02  0:00   ` George Haddad
  1996-10-02  0:00     ` David C. Hoos, Sr.
                       ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: George Haddad @ 1996-10-02  0:00 UTC (permalink / raw)



Richard A. O'Keefe wrote:
> spear@wam.umd.edu (Eric Anthony Spear) writes:
> >Is there a function, either in a package or as an attribute, that can 
> >work like this BASIC function:

> >i = ASC("X")
 
> >That is, the function returns the ASCII value of the given character.
> 
> Values of any discrete type can be converted to integers using the
> 'Pos attribute and back again using the 'Val attribute.  This was so
> in Ada 83 and is still so in Ada 95.   You want
> 
>         I := Character'Pos('X');

   Forgive my ignorance, but is there any guarantee that 
Character'POS('X') = {ASCII code for 'X'}?  Especially now that Ada uses 
ISO Latin-1 (or whatever the standard actually calls for).  Are ASCII 
and Latin-1 two names for the same standard?  (I assume that they are at 
least equivalent for "well-behaved" characters as the solution probably 
works empirically.)

   That having been said, it would obviously be easy to convert between 
the two by providing a lookup table.
-- 
I found these opinions on my doorstep, would you please give them a good 
home?




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: help: character to integer
  1996-10-02  0:00   ` George Haddad
  1996-10-02  0:00     ` David C. Hoos, Sr.
@ 1996-10-02  0:00     ` Robert A Duff
  1996-10-05  0:00     ` Robert Dewar
  2 siblings, 0 replies; 16+ messages in thread
From: Robert A Duff @ 1996-10-02  0:00 UTC (permalink / raw)



In article <3252BEC8.529E@lmco.com>,
George Haddad  <george.haddad@lmco.com> wrote:
>   Forgive my ignorance, but is there any guarantee that 
>Character'POS('X') = {ASCII code for 'X'}?

Yes, that is guaranteed.

>...  Especially now that Ada uses 
>ISO Latin-1 (or whatever the standard actually calls for).  Are ASCII 
>and Latin-1 two names for the same standard?

No, but the 128 Ascii characters are the same as the first 128 Latin-1
characters.  Ascii has 128 characters, and Latin-1 has 256.  So, in
changing from Ascii to Latin-1 (Ada 83 to Ada 95), you're just adding
128 more characters.  The old characters still have the same internal
codes.

And Ada 95 also supports the 16-bit Unicode character set
(i.e. Wide_Character).  The first 256 characters of Unicode are the same
as the Latin-1 character set.

- Bob




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: help: character to integer
  1996-10-02  0:00   ` George Haddad
@ 1996-10-02  0:00     ` David C. Hoos, Sr.
  1996-10-02  0:00     ` Robert A Duff
  1996-10-05  0:00     ` Robert Dewar
  2 siblings, 0 replies; 16+ messages in thread
From: David C. Hoos, Sr. @ 1996-10-02  0:00 UTC (permalink / raw)



George Haddad <george.haddad@lmco.com> wrote in article
<3252BEC8.529E@lmco.com>...
> Richard A. O'Keefe wrote:
> > spear@wam.umd.edu (Eric Anthony Spear) writes:
> > >Is there a function, either in a package or as an attribute, that can 
> > >work like this BASIC function:
> > >i = ASC("X")
> > >That is, the function returns the ASCII value of the given character.
> > Values of any discrete type can be converted to integers using the
> > 'Pos attribute and back again using the 'Val attribute.  This was so
> > in Ada 83 and is still so in Ada 95.   You want
> >         I := Character'Pos('X');
>    Forgive my ignorance, but is there any guarantee that 
> Character'POS('X') = {ASCII code for 'X'}?  Especially now that Ada uses 
> ISO Latin-1 (or whatever the standard actually calls for).  Are ASCII 
> and Latin-1 two names for the same standard?  (I assume that they are at 

Yes, there is a guarantee -- it's called the ANSI/ISO/IEC-8652:1995 Ada 95
Reference Manual, A.3.3,  declaration for the package
Ada.Characters.Latin_1.  The values Character'Val(0) .. Character'Val(127)
are the 7-bit ASCII character set of olden days, and the Latin_1 set
includes the values Character'Val(0) .. Character'Val (255).
-- 
David C. Hoos, Sr.,
http://www.dbhwww.com
http://www.ada95.com






^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: help: character to integer
  1996-10-02  0:00   ` George Haddad
  1996-10-02  0:00     ` David C. Hoos, Sr.
  1996-10-02  0:00     ` Robert A Duff
@ 1996-10-05  0:00     ` Robert Dewar
  1996-10-07  0:00       ` the term "pound sign" (was: help: character to integer) Adam Beneschan
  2 siblings, 1 reply; 16+ messages in thread
From: Robert Dewar @ 1996-10-05  0:00 UTC (permalink / raw)



iGeorge said

"   Forgive my ignorance, but is there any guarantee that
Character'POS('X') = {ASCII code for 'X'}?  Especially now that Ada uses
ISO Latin-1 (or whatever the standard actually calls for).  Are ASCII
and Latin-1 two names for the same standard?  (I assume that they are at
least equivalent for "well-behaved" characters as the solution probably
works empirically.){"


ASCII is essentially an obsolete standard at this point. For all practical
purposes, ASCII is equivalent to the lower 128 characters of Latin-1, and
so for example, the answer to your question about 'X' is a definite yes.

Unlike other languages, the type Character is well defined in Ada, and
not subject to host/target considerations (for example, even on an EBCDIC
machine, an Ada compiler would provide a type Character matching Latin-1)

So there is nothing empirical here, the behavior is completely well defined
by the reference manual.

The reason that I say "for all practical purposes" is that ASCII is a little
bit fuzzy, especially if you roam around different countries. ASCII is 
actually a specialized US version of an (obsolete) international standard
that allows variations from country to country. Some symbols, like $ :-)
are international. But for example, the symbol for 16#23# which is # in
the US version, is the pound stirling symbol in the UK (this is why # on
a US touch tone phone is called the pound key).

Latin-1 on the other hand does not have national variations. This means that
if you are in say Sweden, people will think of ASCII as having symbols for
letters like A-circle. This is not quite correct thinking, because it is not
ASCII anymore, but in any case all these problems disappear when using
Latin-1.

Note: although Latin-1 support is required, Ada compilers may allow
localization options for different character sets. For example the GNMAT
compiler itself allows the following character sets for Ada identifiers

Latin-1
Latin-2
Latin-3
Latin-4
IBM PC (standard US version)
IBM PC code page 850 (European version)
Full upper half

We currently don't provide corresponding library packages for
the children of Ada.Characters for these sets, but we could (if anyone
really needed them, I wonder if anyone using Ada uses Latin-2 or Latin-4???)

But in standard mode, Latin-1 is the set, and you can count on it.





^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: help: character to integer
  1996-10-01  0:00 help: character to integer Eric Anthony Spear
  1996-10-02  0:00 ` Richard A. O'Keefe
  1996-10-02  0:00 ` help: character to integer Dave Marshall
@ 1996-10-07  0:00 ` Paul Tongue
  2 siblings, 0 replies; 16+ messages in thread
From: Paul Tongue @ 1996-10-07  0:00 UTC (permalink / raw)
  To: Eric Anthony Spear


Eric Anthony Spear wrote:
> 
> I've tried to find the answer in the RM, but I haven't had any luck.
> 
> Is there a function, either in a package or as an attribute, that can work
> like this BASIC function:
> 
> i = ASC("X")
> 
> That is, the function returns the ASCII value of the given character.
> 
> Thanks in advance for any help.

Eric,

It has been a while since I've used Ada, but I think the predefined 
attribute POS is what you are looking for.  Here some example code :

declare
  I : INTEGER;
  C : constant CHARACTER := 'A';
  S : constant STRING := "BARNES";
begin
  I := CHARACTER'POS(C);
  -- I should be 65
  I := CHARACTER'POS(S(1));
  -- I should now be 66
end;

Hope this helps.

Paul.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: the term "pound sign" (was: help: character to integer)
  1996-10-05  0:00     ` Robert Dewar
@ 1996-10-07  0:00       ` Adam Beneschan
  1996-10-09  0:00         ` Michael Feldman
  0 siblings, 1 reply; 16+ messages in thread
From: Adam Beneschan @ 1996-10-07  0:00 UTC (permalink / raw)



******************************************************************
* And now, for another installation of . . .                     *
*                                                                *
* PEDANT'S CORNER                                                *
*                                                                *
* the occasional discussion where we talk about nitpicks that    *
* have absolutely nothing to do with the newsgroup               *
******************************************************************


dewar@schonberg.cs.nyu.edu (Robert Dewar) writes:
 >. . . But for example, the symbol for 16#23# which is # in
 >the US version, is the pound stirling symbol in the UK (this is why # on
 >a US touch tone phone is called the pound key).

Hmmm . . . In Webster's Ninth New Collegiate Dictionary, there's a
table "Weights and Measures" with the following line: 


UNIT     ABBR. OR SYMBOL      EQUIVALENTS IN OTHER UNITS      METRIC EQUIVALENT
                                   OF SAME SYSTEM

pound    lb or lb avdp also #    16 ounces, 7000 grains        0.454 kilogram


probably indicating that the use of the term "pound sign" for # did
not arise from an accident of the ASCII chart.  It seems more likely
to me that the common names for the two symbols led the character-code
designers to give them the same ASCII code, not the other way around.
Anyone have any definitive information that would settle this question
of the utmost importance?

                                -- Adam






^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: the term "pound sign" (was: help: character to integer)
  1996-10-07  0:00       ` the term "pound sign" (was: help: character to integer) Adam Beneschan
@ 1996-10-09  0:00         ` Michael Feldman
  1996-10-09  0:00           ` Robert Dewar
  1996-10-11  0:00           ` Robert I. Eachus
  0 siblings, 2 replies; 16+ messages in thread
From: Michael Feldman @ 1996-10-09  0:00 UTC (permalink / raw)



In article <53blbk$6va@krusty.irvine.com>,
Adam Beneschan <adam@irvine.com> wrote:

>pound    lb or lb avdp also #    16 ounces, 7000 grains        0.454 kilogram

>probably indicating that the use of the term "pound sign" for # did
>not arise from an accident of the ASCII chart.  It seems more likely
>to me that the common names for the two symbols led the character-code
>designers to give them the same ASCII code, not the other way around.
>Anyone have any definitive information that would settle this question
>of the utmost importance?

Way back in my high school and undergraduate days (hmmm - 1958-66),
we routinely used # in physics classes to represent pounds. That was
definitely before ASCII. 

Mike Feldman
(gray and aging pedant)




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: the term "pound sign" (was: help: character to integer)
  1996-10-09  0:00           ` Robert Dewar
@ 1996-10-09  0:00             ` Michael Feldman
  1996-10-10  0:00             ` Richard Kenner
  1 sibling, 0 replies; 16+ messages in thread
From: Michael Feldman @ 1996-10-09  0:00 UTC (permalink / raw)



In article <dewar.844907172@merv>, Robert Dewar <dewar@merv.cs.nyu.edu> wrote:

>Telegraphy codes which were the precursors to ASCII were certainly in
>wide use in 1958.

True, but all those physics teachers didn't get the # abbreviation
from telegraph codes. I doubt that there was any connection at that point.

>I must say I suspect that the guess that the # abbreviation for pound
>is older and ISO/ASCII copied this to decide where the stirling sigh
>went seems plausible, but we have no proof ye!

Well, I guess so. I wonder what a "stirling sigh" is.
I bet you meant "Sterling sign".:-)

Mike Feldman




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: the term "pound sign" (was: help: character to integer)
  1996-10-09  0:00         ` Michael Feldman
@ 1996-10-09  0:00           ` Robert Dewar
  1996-10-09  0:00             ` Michael Feldman
  1996-10-10  0:00             ` Richard Kenner
  1996-10-11  0:00           ` Robert I. Eachus
  1 sibling, 2 replies; 16+ messages in thread
From: Robert Dewar @ 1996-10-09  0:00 UTC (permalink / raw)



Mike said

"Way back in my high school and undergraduate days (hmmm - 1958-66),
we routinely used # in physics classes to represent pounds. That was
definitely before ASCII.

Mike Feldman
(gray and aging pedant)"


This is not decisive, Mike is too young for childhood memories to be
early enough :-)

Telegraphy codes which were the precursors to ASCII were certainly in
wide use in 1958.

I must say I suspect that the guess that the # abbreviation for pound
is older and ISO/ASCII copied this to decide where the stirling sigh
went seems plausible, but we have no proof ye!





^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: the term "pound sign" (was: help: character to integer)
  1996-10-10  0:00             ` Richard Kenner
@ 1996-10-10  0:00               ` Adam Beneschan
  0 siblings, 0 replies; 16+ messages in thread
From: Adam Beneschan @ 1996-10-10  0:00 UTC (permalink / raw)



kenner@lab.ultra.nyu.edu (Richard Kenner) writes:
 >In article <dewar.844907172@merv> dewar@merv.cs.nyu.edu (Robert Dewar) writes:
 >>Telegraphy codes which were the precursors to ASCII were certainly in
 >>wide use in 1958.
 >
 >But did those include the "#" character?
 >
 >The list for Morse code I'm looking at includes just the letters, numbers,
 >period, comma, question mark, colon, semicolon, fraction bar, and some
 >symbols not in ASCII.
 >
 >Actually, in telephony "#" is called an "octothorpe".

Interesting!  OK, if I ever design one of those automated touch-tone
computerized system thingys, I'll make the voice on the recording say:

"When you are done entering your credit card number, press the
octothorpe." 

:)
                                -- Adam




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: the term "pound sign" (was: help: character to integer)
  1996-10-09  0:00           ` Robert Dewar
  1996-10-09  0:00             ` Michael Feldman
@ 1996-10-10  0:00             ` Richard Kenner
  1996-10-10  0:00               ` Adam Beneschan
  1 sibling, 1 reply; 16+ messages in thread
From: Richard Kenner @ 1996-10-10  0:00 UTC (permalink / raw)



In article <dewar.844907172@merv> dewar@merv.cs.nyu.edu (Robert Dewar) writes:
>Telegraphy codes which were the precursors to ASCII were certainly in
>wide use in 1958.

But did those include the "#" character?

The list for Morse code I'm looking at includes just the letters, numbers,
period, comma, question mark, colon, semicolon, fraction bar, and some
symbols not in ASCII.

Actually, in telephony "#" is called an "octothorpe".




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: the term "pound sign" (was: help: character to integer)
  1996-10-11  0:00           ` Robert I. Eachus
@ 1996-10-11  0:00             ` Robert Dewar
  0 siblings, 0 replies; 16+ messages in thread
From: Robert Dewar @ 1996-10-11  0:00 UTC (permalink / raw)



Robert Eachus says

"   You can blame Ma Bell for the name octothorpe, but the symbol # for
pounds goes way back.  I'm not sure if I could dig up a printed
reference before 1700, but I am certain I can find one that predates
the telegraph by at least a century.  (Actually the Williams College
Library is a great place to look if you are still in Pownal, Robert.
Just ask for early arithmetic textbooks.)"


Can we please have such a reference, instead of declarations that you
are sure it exists. note that we still, surprisingly, do not have any
shred of evidence to support the claims that the symbol # for pound
goes way back. It sounds reasonable, but it would be nice if someone
could come up with one quote that would settle the issue.





^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: the term "pound sign" (was: help: character to integer)
  1996-10-09  0:00         ` Michael Feldman
  1996-10-09  0:00           ` Robert Dewar
@ 1996-10-11  0:00           ` Robert I. Eachus
  1996-10-11  0:00             ` Robert Dewar
  1 sibling, 1 reply; 16+ messages in thread
From: Robert I. Eachus @ 1996-10-11  0:00 UTC (permalink / raw)



In article <53hnn3$474@news.nyu.edu> kenner@lab.ultra.nyu.edu (Richard Kenner) writes:

  > The list for Morse code I'm looking at includes just the letters,
  > numbers, period, comma, question mark, colon, semicolon, fraction
  > bar, and some symbols not in ASCII.

  > Actually, in telephony "#" is called an "octothorpe".

   You can blame Ma Bell for the name octothorpe, but the symbol # for
pounds goes way back.  I'm not sure if I could dig up a printed
reference before 1700, but I am certain I can find one that predates
the telegraph by at least a century.  (Actually the Williams College
Library is a great place to look if you are still in Pownal, Robert.
Just ask for early arithmetic textbooks.)

--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~1996-10-11  0:00 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-10-01  0:00 help: character to integer Eric Anthony Spear
1996-10-02  0:00 ` Richard A. O'Keefe
1996-10-02  0:00   ` George Haddad
1996-10-02  0:00     ` David C. Hoos, Sr.
1996-10-02  0:00     ` Robert A Duff
1996-10-05  0:00     ` Robert Dewar
1996-10-07  0:00       ` the term "pound sign" (was: help: character to integer) Adam Beneschan
1996-10-09  0:00         ` Michael Feldman
1996-10-09  0:00           ` Robert Dewar
1996-10-09  0:00             ` Michael Feldman
1996-10-10  0:00             ` Richard Kenner
1996-10-10  0:00               ` Adam Beneschan
1996-10-11  0:00           ` Robert I. Eachus
1996-10-11  0:00             ` Robert Dewar
1996-10-02  0:00 ` help: character to integer Dave Marshall
1996-10-07  0:00 ` Paul Tongue

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