comp.lang.ada
 help / color / mirror / Atom feed
From: "DuckE" <nospam_steved94@home.com>
Subject: Re: Hi byte and Lo Byte Question
Date: Thu, 23 Aug 2001 01:26:31 GMT
Date: 2001-08-23T01:26:31+00:00	[thread overview]
Message-ID: <bZYg7.2551$e91.833252@news1.sttln1.wa.home.com> (raw)
In-Reply-To: 9m0gn6$b6j$1@zeus.orl.lmco.com

You don't really say anything about the data types you're working with, so
I'll just assume you're using Interfaces.Unsigned_16.  This sample Ada
program fairly closely matches the C example you gave, although you didn't
give any examples of types.

with Interfaces;
 use Interfaces;
with Ada.Text_Io;

procedure testbytes is

  package Unsigned_16_Io is new Ada.Text_Io.Modular_Io( Unsigned_16 );

  function LOBYTE( value : Unsigned_16 ) return Unsigned_16 is
  pragma Inline( LOBYTE );
  begin
    return value and 16#FF#;
  end LOBYTE;

  function HIBYTE( value : Unsigned_16 ) return Unsigned_16 is
  pragma Inline(HIBYTE);
  begin
    return Shift_Right( value, 8 );
  end HIBYTE;

begin
  declare
    a : Unsigned_16;
  begin
    a := 16#0102#;
    Ada.Text_Io.Put( "Value:  " );
    Unsigned_16_Io.Put( a, 8, 16 );
    Ada.Text_Io.New_Line;
    Ada.Text_Io.Put( "LOBYTE: " );
    Unsigned_16_Io.Put( LOBYTE( a ), 8, 16 );
    Ada.Text_Io.New_Line;
    Ada.Text_Io.Put( "HIBYTE: " );
    Unsigned_16_Io.Put( HIBYTE( a ), 8, 16 );
    Ada.Text_Io.New_Line;
  end;
end testbytes;

BTW: In Ada things are usually described in a more abstract manner, except
sometimes when dealing with interfaces.

SteveD


"mop" <mop65715@pegasus.cc.ucf.edu> wrote in message
news:9m0gn6$b6j$1@zeus.orl.lmco.com...
>
> I need to parse data into hi byte and lo byte. Does Ada have some built in
> macros or .... I could use?  From the looks of it no.
>
> here's the C version .... Need the Ada version as am new to Ada.
>
> lo = LOBYTE(Value);   -- need Ada version for this LOBYTE macro
> hi = HIBYTE(Value);    -- need Ada version for this HIBYTE macro
> WORD.Data.Word5_Data_Value_In_HB_LB_Order[0] = hi;
> WORD.Data.Word5_Data_Value_In_HB_LB_Order[1] = lo;
>
>
>





      parent reply	other threads:[~2001-08-23  1:26 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-22 14:48 Hi byte and Lo Byte Question mop
2001-08-22 15:56 ` Larry Kilgallen
2001-08-22 16:21 ` Ted Dennison
2001-08-22 23:11 ` Mark Johnson
2001-08-23  0:23   ` Darren New
2001-08-23 14:13     ` Mark Johnson
2001-08-23 17:15       ` Darren New
2001-08-24  0:00       ` Robert Dewar
2001-08-24  7:52         ` Martin Dowie
2001-08-23 14:43   ` Marin David Condic
2001-08-24  8:09     ` Peter Dulimov
2001-08-24 16:20       ` Warren W. Gay VE3WWG
2001-08-24 17:05         ` Marin David Condic
2001-08-24 17:46           ` Warren W. Gay VE3WWG
2001-08-25  7:15             ` Simon Wright
2001-08-27 16:33               ` Warren W. Gay VE3WWG
2001-08-23  1:26 ` DuckE [this message]
replies disabled

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