From: Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov>
Subject: Re: convert integer base10 into base16
Date: 12 Feb 2002 11:45:31 -0500
Date: 2002-02-12T16:50:11+00:00 [thread overview]
Message-ID: <ubseuir84.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: 8fe5cfbb.0202120405.19690c26@posting.google.com
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
next prev parent reply other threads:[~2002-02-12 16:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-02-12 12:05 convert integer base10 into base16 c-kif-kif
2002-02-12 12:10 ` Lutz Donnerhacke
2002-02-12 13:53 ` Alfred Hilscher
2002-02-12 14:33 ` Georg Bauhaus
2002-02-12 16:45 ` Stephen Leake [this message]
2002-02-13 6:17 ` Dale Stanbrough
2002-02-13 9:44 ` c-kif-kif
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox