Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Integer Value to Hexadecimal in Ada

Tags:

hex

ada

There is some kind of workaround to take advantage of the following and saving it?

Put_Line(MyNum, Base => 16);

which is converting for instance 255 to its proper value in hexadecimal FF, but just for display purposes. Can I do something similar, but to save the result?

like image 530
SpcCode Avatar asked Dec 14 '12 02:12

SpcCode


Video Answer


2 Answers

You could use the version of Put that outputs to a string:

procedure Put(To   : out String;
              Item : in Num;
              Base : in Number_Base := Default_Base);
like image 134
Simon Wright Avatar answered Oct 10 '22 18:10

Simon Wright


Can I do something similar, but to save the result?

Yes, it's not "the simplest" way, but it's very general and flexible if you use Streams.

The wikibook has an example, though it's a little 'wordy' for what you intend: http://en.wikibooks.org/wiki/Ada_Programming/Libraries/Ada.Streams/Example


The simple "one-liner" is Ada.Integer_Text_IO.Put.

Ada95's RM describes integer_text_IO in Annex A, 10.8.

like image 26
Shark8 Avatar answered Oct 10 '22 18:10

Shark8