* Re: Ascii keyword??
2001-02-16 18:34 Ascii keyword?? Richard
@ 2001-02-16 18:46 ` Pascal Obry
2001-02-16 18:52 ` Marin David Condic
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Pascal Obry @ 2001-02-16 18:46 UTC (permalink / raw)
Richard <richard-blunt@blueyonder.co.uk> writes:
> ok am new to this ada thing, so is there a package and/or keyword i can
> use to convert a decimal number to a acsii character and vice versa
Nothing like that, but there is some attributes for that. Look for
'Val and 'Pos attributes in any Ada textbook.
Pascal.
--
--|------------------------------------------------------
--| Pascal Obry Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--| http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Ascii keyword??
2001-02-16 18:34 Ascii keyword?? Richard
2001-02-16 18:46 ` Pascal Obry
@ 2001-02-16 18:52 ` Marin David Condic
2001-02-16 19:29 ` Lao Xiao Hai
2001-02-16 23:22 ` David C. Hoos, Sr.
3 siblings, 0 replies; 7+ messages in thread
From: Marin David Condic @ 2001-02-16 18:52 UTC (permalink / raw)
"Richard" <richard-blunt@blueyonder.co.uk> wrote in message
news:3A8D72D4.BBB57470@blueyonder.co.uk...
> ok am new to this ada thing, so is there a package and/or keyword i can
> use to convert a decimal number to a acsii character and vice versa
>
It's pretty simple. There are things in Ada called "Attributes" which can be
extremely handy for a wide variety of things. In this case, there are two
attributes which are defined for all discrete types (characters being a
discrete type). They are 'Pos and 'Val and they work like function calls.
Here's basically how you would use them.
My_Int : Integer := 0 ;
My_Char : Character := ' ' ;
...
My_Char := Character'Val (33) ; -- Gives My_Char the ascii character '!'
My_Int := Character'Pos ('&') ; -- Gives My_Int the value 38.
A good example of this is in the appendix A.3.3 of the ARM. (This is where
the Latin_1 character set is defined.) If you don't have an ARM handy, look
at: http://www.adapower.org/ under "Reference" for the on-line HTML version
of the ARM. While the ARM is not the best source for teaching yourself Ada,
it is a valuable resource for looking up particulars that you may come
across in reading other texts.
Good luck with Ada!
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/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Ascii keyword??
2001-02-16 18:34 Ascii keyword?? Richard
2001-02-16 18:46 ` Pascal Obry
2001-02-16 18:52 ` Marin David Condic
@ 2001-02-16 19:29 ` Lao Xiao Hai
2001-02-16 23:22 ` David C. Hoos, Sr.
3 siblings, 0 replies; 7+ messages in thread
From: Lao Xiao Hai @ 2001-02-16 19:29 UTC (permalink / raw)
Richard wrote:
> ok am new to this ada thing, so is there a package and/or keyword i can
> use to convert a decimal number to a acsii character and vice versa
>
> thanks :)
The problem of converting a numeric value to a string and vice versa is
quite
nicely addressed in package Ada.Text_IO. For example, if you have a
floating
point type, you can instantiate Ada.Text_IO.Float_IO. There are GET and
PUT
operations available from that instantiation to convert a string to a
floating point
value or get a floating point value from a string.
This same feature is available for all the numeric types: integers,
decimal, fixed-point,
and modular.
Richard Riehle
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Ascii keyword??
2001-02-16 18:34 Ascii keyword?? Richard
` (2 preceding siblings ...)
2001-02-16 19:29 ` Lao Xiao Hai
@ 2001-02-16 23:22 ` David C. Hoos, Sr.
2001-02-17 0:54 ` Jeffrey Carter
2001-02-17 4:51 ` Lao Xiao Hai
3 siblings, 2 replies; 7+ messages in thread
From: David C. Hoos, Sr. @ 2001-02-16 23:22 UTC (permalink / raw)
What you need is the language-defined function
Character'Val (<integer_expression>) to convert
a number in the range 0 .. 255 to its corresponding
character, and the language-defined function
Character'Pos (<character_value>) to obtain its
position in the character set -- 0 .. 255;
E.g., Character'Val (65) returns 'A', and
Character'Pos ('A') returns 65.
"Richard" <richard-blunt@blueyonder.co.uk> wrote in message
news:3A8D72D4.BBB57470@blueyonder.co.uk...
> ok am new to this ada thing, so is there a package and/or keyword i can
> use to convert a decimal number to a acsii character and vice versa
>
>
> thanks :)
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Ascii keyword??
2001-02-16 23:22 ` David C. Hoos, Sr.
@ 2001-02-17 0:54 ` Jeffrey Carter
2001-02-17 4:51 ` Lao Xiao Hai
1 sibling, 0 replies; 7+ messages in thread
From: Jeffrey Carter @ 2001-02-17 0:54 UTC (permalink / raw)
"David C. Hoos, Sr." wrote:
>
> What you need is the language-defined function ...
What he needs is to check out the Ada FAQ at www.adapower.com. If this
isn't in there, it should be.
--
Jeff Carter
"Hello! Smelly English K...niggets."
Monty Python & the Holy Grail
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Ascii keyword??
2001-02-16 23:22 ` David C. Hoos, Sr.
2001-02-17 0:54 ` Jeffrey Carter
@ 2001-02-17 4:51 ` Lao Xiao Hai
1 sibling, 0 replies; 7+ messages in thread
From: Lao Xiao Hai @ 2001-02-17 4:51 UTC (permalink / raw)
"David C. Hoos, Sr." wrote:
> What you need is the language-defined function
> Character'Val (<integer_expression>) to convert
> a number in the range 0 .. 255 to its corresponding
> character, and the language-defined function
> Character'Pos (<character_value>) to obtain its
> position in the character set -- 0 .. 255;
>
> E.g., Character'Val (65) returns 'A', and
> Character'Pos ('A') returns 65.
>
David,
I made the assumption he needed to convert ascii strings to numbers. That
might have been incorrect. Often, when teaching Ada, I find that this kind
of question, when posed by someone from a C/C++ background, is not really
about the one-to-one correspondence between the character name and the
numeric ASCII value, but rather about making numbers from strings and
vice-versa.
^ permalink raw reply [flat|nested] 7+ messages in thread