* Re: creating a 16 bit value from 2 8 bit values in Ada
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
` (3 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Darren New @ 2002-08-02 2:07 UTC (permalink / raw)
Mark wrote:
> 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
Wouldn't it be something along the lines of
result := lo + 256 * hi;
?
--
Darren New
San Diego, CA, USA (PST). Cryptokeys on demand.
** http://home.san.rr.com/dnew/DNResume.html **
** http://images.fbrtech.com/dnew/ **
Things to be thankful for, #37:
No sausage was served at the Last Supper.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: creating a 16 bit value from 2 8 bit values in Ada
2002-08-02 2:07 ` Darren New
@ 2002-08-02 8:36 ` John McCabe
0 siblings, 0 replies; 8+ messages in thread
From: John McCabe @ 2002-08-02 8:36 UTC (permalink / raw)
On Fri, 02 Aug 2002 02:07:24 GMT, Darren New <dnew@san.rr.com> wrote:
>Mark wrote:
>> 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
>
>Wouldn't it be something along the lines of
> result := lo + 256 * hi;
That's pretty much what I would have said!
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: creating a 16 bit value from 2 8 bit values in Ada
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 18:21 ` Stephen Leake
2002-08-03 14:37 ` Robert Dewar
2002-08-03 0:52 ` Kevin Krieser
` (2 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Stephen Leake @ 2002-08-02 18:21 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: creating a 16 bit value from 2 8 bit values in Ada
2002-08-02 18:21 ` Stephen Leake
@ 2002-08-03 14:37 ` Robert Dewar
0 siblings, 0 replies; 8+ messages in thread
From: Robert Dewar @ 2002-08-03 14:37 UTC (permalink / raw)
Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov> wrote in message news:<uwur96s19.fsf@gsfc.nasa.gov>...
> One advantage of this version is it should take no code.
No, it is probably much less efficient, because it forces
things into memory.
> One drawback
> is you have to get the byte-endianness right.
A big drawback. This is definitely not the right approach.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: creating a 16 bit value from 2 8 bit values in Ada
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 18:21 ` Stephen Leake
@ 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
4 siblings, 0 replies; 8+ messages in thread
From: Kevin Krieser @ 2002-08-03 0:52 UTC (permalink / raw)
To: Mark
Mark wrote:
> 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?
>
>
> type SOME_TYPE is
> record
> Lo : BYTE;
> Hi : BYTE;
> X : BOOLEAN;
> -- more stuff
> end record;
>
> for SOME_TYPE use
> record
> Lo at 0 range 0 .. 6;
> Hi at 0 range 7 .. 15;
> -- more stuff
> end record;
Sorry to be picky, but the above wouldn't work. Byte wouldn't fit in 7
bits.
If you have some unsigned 16 bit type, called something like unsigned16,
you could just do a big_val := unsigned16(hi) * 256 + unsigned16(lo);
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: creating a 16 bit value from 2 8 bit values in Ada
2002-08-02 1:40 creating a 16 bit value from 2 8 bit values in Ada Mark
` (2 preceding siblings ...)
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
4 siblings, 0 replies; 8+ messages in thread
From: SteveD @ 2002-08-03 1:59 UTC (permalink / raw)
"Mark" <ma740988@pegasus.cc.ucf.edu> wrote in message
news:a5ae824.0208011740.7f2df9dc@posting.google.com...
> 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?
>
>
> type SOME_TYPE is
> record
> Lo : BYTE;
> Hi : BYTE;
> X : BOOLEAN;
> -- more stuff
> end record;
>
> for SOME_TYPE use
> record
> Lo at 0 range 0 .. 6;
> Hi at 0 range 7 .. 15;
> -- more stuff
> end record;
>
> In an earlier post i made a reference to 'intrinsics' that might aid
> in my objective, but that appears to be a tartan utility.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: creating a 16 bit value from 2 8 bit values in Ada (again)
2002-08-02 1:40 creating a 16 bit value from 2 8 bit values in Ada Mark
` (3 preceding siblings ...)
2002-08-03 1:59 ` SteveD
@ 2002-08-03 2:02 ` SteveD
4 siblings, 0 replies; 8+ messages in thread
From: SteveD @ 2002-08-03 2:02 UTC (permalink / raw)
Sorry about my previous accidental send.
Here is how I would do it (the following compiles and runs on GNAT
3.14p-nt):
with Ada.Text_Io;
with Interfaces;
use Interfaces;
procedure Test is
function To_Unsigned_16( lsb, msb : Unsigned_8 ) return Unsigned_16 is
begin
return Shift_Left( Unsigned_16( msb ), 8 ) or Unsigned_16( lsb );
end To_Unsigned_16;
begin
Ada.Text_Io.Put_Line( Unsigned_16'IMAGE( To_Unsigned_16( 16#01#,
16#00# ) ) );
Ada.Text_Io.Put_Line( Unsigned_16'IMAGE( To_Unsigned_16( 16#00#,
16#01# ) ) );
end Test;
SteveD
^ permalink raw reply [flat|nested] 8+ messages in thread