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: 17 Oct 91 04:34:35 GMT From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!usen et.coe.montana.edu!milton!mfeldman@ucbvax.Berkeley.EDU (Michael Feldman) Subject: Re: Converting integers to char's Message-ID: <1991Oct17.043435.20305@milton.u.washington.edu> List-Id: 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) -------------------------------------------------------------------------------