comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov>
Subject: Re: creating a 16 bit value from 2 8 bit values in Ada
Date: 02 Aug 2002 14:21:06 -0400
Date: 2002-08-02T18:29:35+00:00	[thread overview]
Message-ID: <uwur96s19.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: a5ae824.0208011740.7f2df9dc@posting.google.com

ma740988@pegasus.cc.ucf.edu (Mark) writes:

> Could someone show me how to concatenate the Hi and Lo components? 
> The end result - obviously - would be a 16 bit value.  I've waded
> through my ada books here and keep coming up short?

Others have pointed out ' lo + 256 * hi'. Another choice is:

type Double_Byte_Type is record
    Lo : Byte;
    Hi : Byte;
end record;
for Double_Byte_Type use record
    Lo at 0 range 0 .. 6;
    Hi at 0 range 7 .. 15;
end record;  
for Double_Byte_Type'size use 16;

function to_int_16 is new Ada.Unchecked_conversions
   (Source => Double_Byte_Type,
    Target => Interfaces.Unsigned_16);

type Some_Type is record
   Hi_Lo : Double_Byte_Type;
   -- more stuff
end record;


One advantage of this version is it should take no code. One drawback
is you have to get the byte-endianness right.

-- 
-- Stephe



  parent reply	other threads:[~2002-08-02 18:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-02  1:40 creating a 16 bit value from 2 8 bit values in Ada Mark
2002-08-02  2:07 ` Darren New
2002-08-02  8:36   ` John McCabe
2002-08-02 18:21 ` Stephen Leake [this message]
2002-08-03 14:37   ` Robert Dewar
2002-08-03  0:52 ` Kevin Krieser
2002-08-03  1:59 ` SteveD
2002-08-03  2:02 ` creating a 16 bit value from 2 8 bit values in Ada (again) SteveD
replies disabled

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