comp.lang.ada
 help / color / mirror / Atom feed
From: bu.edu!inmet!inmet!stt@bloom-beacon.mit.edu
Subject: Re: converting integer to character
Date: 22 Oct 91 12:39:00 GMT	[thread overview]
Message-ID: <20600122@inmet> (raw)

Re: "converting integer to character" by maysee@m11.sews.wpafb.af.mil
> Chris,
> 
> --   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.
> 
>      Assuming you are trying to convert an integer 1 to a character 1.
> The following statement should work.
> 
>         My_char := number'image;
> 
>      Where My_char is defined as a string of length 2.  You must allow
> an extra character for the sign bit.  Otherwise you will receive a
> constraint error.  The above statement would work for integers 0 thru 9,
> assuming you defined a string of length 2.

The above response is a bit "erroneous" :-).

If you want to convert from an integer to the character with the
corresponding ASCII code, then you may do the following:

     Chr : constant Character := Character'VAL(Int);

If you want to convert from an integer to a string representation
of its value, then you may do the following:

     Str : constant String := Integer'IMAGE(Int);

presuming Int is of type Integer.

> Eric Mays
> maysee@m11.sews.wpafb.af.mil

S. Tucker Taft    stt@inmet.inmet.com
Intermetrics, Inc.
Cambridge, MA  02138
> /* End of text from inmet:comp.lang.ada */

             reply	other threads:[~1991-10-22 12:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1991-10-22 12:39 bu.edu!inmet!inmet!stt [this message]
  -- strict thread matches above, loose matches on Subject: below --
1991-10-17 11:52 converting integer to character Eric E. Mays 52202
replies disabled

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