From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,252713cea9bdfef9 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-02-12 08:46:27 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!hammer.uoregon.edu!skates!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: convert integer base10 into base16 Date: 12 Feb 2002 11:45:31 -0500 Organization: NASA Goddard Space Flight Center Message-ID: References: <8fe5cfbb.0202120405.19690c26@posting.google.com> NNTP-Posting-Host: anarres.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: skates.gsfc.nasa.gov 1013532611 7899 128.183.220.71 (12 Feb 2002 16:50:11 GMT) X-Complaints-To: dscoggin@cne-odin.gsfc.nasa.gov NNTP-Posting-Date: 12 Feb 2002 16:50:11 GMT User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 Xref: archiver1.google.com comp.lang.ada:19945 Date: 2002-02-12T16:50:11+00:00 List-Id: c-kif-kif@eudoramail.com (c-kif-kif) writes: > I'm shure this question has been answered a million times, > but i still can't get it right. > > It's easy to convert base10 into base16 : > a : integer := 16#A#; > a := Integer'Value (Integer'Image(a)); -- result 10 > > But how can i convert from base10 to base16 or other ? > > I don't want to write it on screen, so i think it's not with put/get > how it works. It is _only_ when you write it to a screen or a string that the notion of base 10 or base 16 matters. When an integer is stored in a variable, such as 'a' above, it is represented as a particular pattern of bits in RAM, normally base 2 binary. Ada.Integer_Text_IO can write to a string as well as to the screen or a file: with Ada.Text_IO; with Ada.Integer_Text_IO; procedure Hex_Image is A : Integer := 10; Image_A : String (1 .. 10); -- bigger than needed, padded with spaces begin Ada.Integer_Text_IO.Put (To => Image_A, Item => A, Base => 16); Ada.Text_IO.Put_Line ("The image we get is '" & Image_A & "'"); end Hex_Image; -- -- Stephe