comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam@spam.com>
Subject: Re: Printing out an Array
Date: Tue, 01 Feb 2005 03:05:20 GMT
Date: 2005-02-01T03:05:20+00:00	[thread overview]
Message-ID: <QlCLd.3466$cl1.3219@newsread3.news.pas.earthlink.net> (raw)
In-Reply-To: <1107182585.066205.21490@f14g2000cwb.googlegroups.com>

conchale@mac.com wrote:

> Hello all, I'm new to this and comming from Java environment.  I have
> this code to convert bytes to bits but I dont know what to put in the
> last line of code to get on the screen my converted number.  Thanks for
> any help

Assuming this isn't homework, in the package Ada.Text_IO (ARM A.10.1) 
you will find the generic packages Integer_IO and Modular_IO (described 
in more detail in ARM A.10.8). If you look at the Put procedures, you 
will find the parameter Base. This allows you to specify the number base 
to represent the number in. If you supply the value 2 for Base, you will 
get the number output in binary.

A typical value from Put with Base => 2 might be " 2#10101010#". If you 
need to get rid of the leading " 2#" and the trailing '#', you can use 
the Put that writes to a String and manipulate the result. 
Alternatively, you can use an Image function from PragmARC.Images, which 
does it for you.

So, in Ada it is not necessary to convert the value to an array of bits 
(which could be accomplished with Ada.Unchecked_Conversion), nor to 
output the bits individually. Yet another case where Ada is simpler and 
more expressive than other languages.

The PragmAda Reusable Components are available from

http://home.earthlink.net/~jrcarter010/pragmarc.htm

-- 
Jeff Carter
"You couldn't catch clap in a brothel, silly English K...niggets."
Monty Python & the Holy Grail
19



  parent reply	other threads:[~2005-02-01  3:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-31 14:43 Printing out an Array conchale
2005-01-31 15:00 ` Martin Krischik
2005-02-01  3:05 ` Jeffrey Carter [this message]
2005-02-01  3:14 ` Steve
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox