comp.lang.ada
 help / color / mirror / Atom feed
* Integer data type
@ 2002-10-11 15:21 Mark
  2002-10-11 15:33 ` Martin Dowie
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Mark @ 2002-10-11 15:21 UTC (permalink / raw)


Is it possible to extract the binary representation of an integer
variable and store that binary representation in another variable?

Thanks,

Mark



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Integer data type
  2002-10-11 15:21 Integer data type Mark
@ 2002-10-11 15:33 ` Martin Dowie
  2002-10-11 16:50 ` Georg Bauhaus
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Martin Dowie @ 2002-10-11 15:33 UTC (permalink / raw)


"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, you should check out:

procedure Put (To : out String; Item : in Num; Base : in Number_Base :=
Default_Base);

in package "Ada.Text_IO.Integer_IO", Annex A of the RM.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Integer data type
  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
  2002-10-14 18:54 ` Stephen Leake
  3 siblings, 0 replies; 7+ messages in thread
From: Georg Bauhaus @ 2002-10-11 16:50 UTC (permalink / raw)


Mark <msims@uoguelph.ca> wrote:
: Is it possible to extract the binary representation of an integer
: variable and store that binary representation in another variable?

Is Martin Dowie's response describing what you want to achieve
or are you thinking of disregarding the integer quality of some
bits? In this case an Unchecked_Conversion might do.

-- Georg



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Integer data type
  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
  2002-10-14 18:54 ` Stephen Leake
  3 siblings, 0 replies; 7+ messages in thread
From: SteveD @ 2002-10-12  2:03 UTC (permalink / raw)


"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






^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Integer data type
  2002-10-11 15:21 Integer data type Mark
                   ` (2 preceding siblings ...)
  2002-10-12  2:03 ` SteveD
@ 2002-10-14 18:54 ` Stephen Leake
  2002-10-15 13:13   ` Matthew Heaney
  3 siblings, 1 reply; 7+ messages in thread
From: Stephen Leake @ 2002-10-14 18:54 UTC (permalink / raw)


msims@uoguelph.ca (Mark) writes:

> Is it possible to extract the binary representation of an integer
> variable and store that binary representation in another variable?

Hmm. To be extremely literal, this does what you are asking:

declare
    A : integer := 1;
    B : integer;
begin
    B := A;
end;

Now B has the same binary representation of an integer that A has.
Note that "binary representation" means "a pattern of bits, usually
stored in memory".

But I suspect you meant something else. 

Can you say more about what you are trying to do?

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Integer data type
  2002-10-14 18:54 ` Stephen Leake
@ 2002-10-15 13:13   ` Matthew Heaney
  2002-10-15 15:59     ` Mark Biggar
  0 siblings, 1 reply; 7+ messages in thread
From: Matthew Heaney @ 2002-10-15 13:13 UTC (permalink / raw)



"Stephen Leake" <stephen.a.leake.1@gsfc.nasa.gov> wrote in message
news:uit04yhod.fsf@gsfc.nasa.gov...
> msims@uoguelph.ca (Mark) writes:
>
> > Is it possible to extract the binary representation of an integer
> > variable and store that binary representation in another variable?
>
>
> But I suspect you meant something else.

He probably needs Unchecked_Conversion.







^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Integer data type
  2002-10-15 13:13   ` Matthew Heaney
@ 2002-10-15 15:59     ` Mark Biggar
  0 siblings, 0 replies; 7+ messages in thread
From: Mark Biggar @ 2002-10-15 15:59 UTC (permalink / raw)


Matthew Heaney wrote:
> "Stephen Leake" <stephen.a.leake.1@gsfc.nasa.gov> wrote in message
> news:uit04yhod.fsf@gsfc.nasa.gov...
> 
>>msims@uoguelph.ca (Mark) writes:
>>
>>
>>>Is it possible to extract the binary representation of an integer
>>>variable and store that binary representation in another variable?
>>
>>
>>But I suspect you meant something else.
> 
> 
> He probably needs Unchecked_Conversion.

No, all integers types are freely inter-convertable (modulo CE due
to range checks) so I don't think he needs Unchecked_Conversion, unless
he wants to convert from integer to a complete different form of type
like "array of boolean".  He probably wants to convert to a string of
"1" & "0" characters, in which case he should use Text_IO.Put to a
string with Base => 2.




-- 
Mark Biggar
mark.a.biggar@attbi.com




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-10-15 15:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2002-10-14 18:54 ` Stephen Leake
2002-10-15 13:13   ` Matthew Heaney
2002-10-15 15:59     ` Mark Biggar

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