comp.lang.ada
 help / color / mirror / Atom feed
From: "SteveD" <nospam_steved94@attbi.com>
Subject: Re: Integer data type
Date: Sat, 12 Oct 2002 02:03:52 GMT
Date: 2002-10-12T02:03:52+00:00	[thread overview]
Message-ID: <cqLp9.8158$NW3.1949@sccrnsc03> (raw)
In-Reply-To: 7bd7d86e.0210110721.8097797@posting.google.com

"Mark" <msims@uoguelph.ca> wrote in message
news:7bd7d86e.0210110721.8097797@posting.google.com...
> Is it possible to extract the binary representation of an integer
> variable and store that binary representation in another variable?
>

Yes.

See http://www.adaic.org/standards/95lrm/html/RM-13-9.html for a description
of Ada.Unchecked_Conversion.

Here is a small example (tested)

with Interfaces;
 use Interfaces;
with Ada.Unchecked_Conversion;
with Ada.Text_Io;

procedure tobytes is

  package Int_16_Io is new Ada.Text_Io.Integer_Io( Integer_16 );
  package Int_32_Io is new Ada.Text_Io.Integer_Io( Integer_32 );
  type Two_16s is array( 1 .. 2 ) of Integer_16;
  function Conv is new Ada.Unchecked_Conversion( Integer_32, Two_16s );

  in_32   : Integer_32;
  out_16s : Two_16s;

begin
  Ada.Text_Io.Put( "Enter value: " );
  Int_32_Io.Get( in_32 );
  out_16s := Conv( in_32 );
  Ada.Text_Io.Put( "The values are: " );
  Int_16_Io.Put( out_16s( 1 ) );
  Ada.Text_Io.Put( ", " );
  Int_16_Io.Put( out_16s( 2 ) );
  Ada.Text_Io.New_Line;
end tobytes;

> Thanks,
>
> Mark

You're welcome.

SteveD






  parent reply	other threads:[~2002-10-12  2:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-11 15:21 Integer data type Mark
2002-10-11 15:33 ` Martin Dowie
2002-10-11 16:50 ` Georg Bauhaus
2002-10-12  2:03 ` SteveD [this message]
2002-10-14 18:54 ` Stephen Leake
2002-10-15 13:13   ` Matthew Heaney
2002-10-15 15:59     ` Mark Biggar
replies disabled

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