comp.lang.ada
 help / color / mirror / Atom feed
* Converting integers to char's
@ 1991-10-16  1:33 agate!spool.mu.edu!sol.ctr.columbia.edu!samsung!munnari.oz.au!mel.dit.csi
  0 siblings, 0 replies; 2+ messages in thread
From: agate!spool.mu.edu!sol.ctr.columbia.edu!samsung!munnari.oz.au!mel.dit.csi @ 1991-10-16  1:33 UTC (permalink / raw)


   Is there any easy way to convert an integer variable to a character.
   I am new to ada and would like to do this without a case statement.
                        thanks Chris.


/***************************************************************************/
/* Chris Fiddyment.  Austin College   | Why'd you kill the man Billy?      */
/* Armidale, Australia.               | Cause he was hackin' on me.        */
/* cfiddyme@gara.une.oz.au            |           -"Young Guns"            */
/***************************************************************************/

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

* Re: Converting integers to char's
@ 1991-10-17  4:34 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!usen
  0 siblings, 0 replies; 2+ messages in thread
From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!usen @ 1991-10-17  4:34 UTC (permalink / raw)


In article <9426@gara.une.oz.au> cfiddyme@gara.une.oz.au (Kith Kanan) writes:
>
>   Is there any easy way to convert an integer variable to a character.
>   I am new to ada and would like to do this without a case statement.
>                        thanks Chris.
>
I assume that what you're looking for is an Ada equivalent to Pascal's
CHR function, or Basic's CHR$ function, to which you pass a nonnegative
integer (presumably in the range 0..127) and get back the corresponding
ASCII character.

Yes, there's an easy way. It's called the Val attribute. Given some
integer X and a character variable Ch,
   Ch := Character'Val(X);
will do the trick, raising Constraint_Error if X's value is out of the
ASCII range.

By the way, going the other way is equally easy.
   X := Character'Pos(Ch);
stores in X the position of Ch in the type Character, which in effect
gets you the ASCII value.

Pos, Val, and lots of other attributes are defined uniformly for
discrete types (integers, enumerations).

Attributes are neat in Ada (though I think they could be neater if they
were more complete and uniform). Check your Ada book or the LRM on this.

Mike

-------------------------------------------------------------------------------
Michael B. Feldman
Visiting Professor 1991-92               Professor
Dept. of Comp. Sci. and Engrg.           Dept. of Elect. Engrg. and Comp. Sci.
University of Washington FR-35           The George Washington University
Seattle, WA 98105                        Washington, DC 20052

mfeldman@cs.washington.edu               mfeldman@seas.gwu.edu
(206) 632-3794 (voice)                   (202) 994-5253 (voice)
(206) 543-2969 (fax)                     (202) 994-5296 (fax)
-------------------------------------------------------------------------------

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

end of thread, other threads:[~1991-10-17  4:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1991-10-17  4:34 Converting integers to char's cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!usen
  -- strict thread matches above, loose matches on Subject: below --
1991-10-16  1:33 agate!spool.mu.edu!sol.ctr.columbia.edu!samsung!munnari.oz.au!mel.dit.csi

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