From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 22 Oct 91 12:39:00 GMT From: bu.edu!inmet!inmet!stt@bloom-beacon.mit.edu Subject: Re: converting integer to character Message-ID: <20600122@inmet> List-Id: 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 */