comp.lang.ada
 help / color / mirror / Atom feed
* converting integer to character
@ 1991-10-17 11:52 Eric E. Mays 52202
  0 siblings, 0 replies; 2+ messages in thread
From: Eric E. Mays 52202 @ 1991-10-17 11:52 UTC (permalink / raw)


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.

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

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

* Re: converting integer to character
@ 1991-10-22 12:39 bu.edu!inmet!inmet!stt
  0 siblings, 0 replies; 2+ messages in thread
From: bu.edu!inmet!inmet!stt @ 1991-10-22 12:39 UTC (permalink / 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 */

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

end of thread, other threads:[~1991-10-22 12:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1991-10-17 11:52 converting integer to character Eric E. Mays 52202
  -- strict thread matches above, loose matches on Subject: below --
1991-10-22 12:39 bu.edu!inmet!inmet!stt

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