Re: Printing out an Array

From: Jeffrey Carter (spam_at_spam.com)
Date: 02/01/05


Date: Tue, 01 Feb 2005 03:05:20 GMT

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


Relevant Pages

  • Re: ADA Popularity Discussion Request
    ... ARM 3.9reads: ... identifies the specific tagged type used to create the object originally. ... The tag of an operand of a class-wide tagged type TąClass controls which ... Dynamic type creation in Ada: ...
    (comp.lang.ada)
  • Re: vhdl questions from a verilog person
    ... I think generic packages and subprograms will ... and we stayed consistent with that for packages and subprograms. ... We have proposals for adding OO to VHDL as well as adding constrained ... I doubt there's the same need for constrained random testing in Ada - ...
    (comp.lang.vhdl)
  • Re: generic package with procedure paramter gives "not subtype conformant with declaration"
    ... Robert A Duff wrote: ... I would be greatfull for an ... arm on how generic packages are elaborated. ... Now if i could just memorize the ARM ... ...
    (comp.lang.ada)
  • Re: Ada access vs C/C++ pointers and references
    ... Study Chapter 13 of the ARM. ... Most Ada books - while being good with the general language features - ...
    (comp.lang.ada)
  • Re: PSoC or FPGA?
    ... GNU compiler chain has a full ... The last time I checked there was no 'real' Ada for ARM. ... Ada Core also has native windows IDE environment (if you like ...
    (sci.electronics.design)