From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4e9860765413318c X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-22 16:10:58 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!pln-w!extra.newsguy.com!lotsanews.com!cyclone-sf.pbi.net!151.164.30.35!cyclone.swbell.net!bos-service1.ext.raytheon.com!dfw-service2.ext.raytheon.com.POSTED!not-for-mail Message-ID: <3B843C0C.9A3282B@raytheon.com> From: Mark Johnson Reply-To: mark_h_johnson@raytheon.com X-Mailer: Mozilla 4.78 [en] (X11; U; Linux 2.4.6-3.1smp i686) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Hi byte and Lo Byte Question References: <9m0gn6$b6j$1@zeus.orl.lmco.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Wed, 22 Aug 2001 18:11:08 -0500 NNTP-Posting-Host: 192.27.48.41 X-Complaints-To: news@ext.ray.com X-Trace: dfw-service2.ext.raytheon.com 998521852 192.27.48.41 (Wed, 22 Aug 2001 18:10:52 CDT) NNTP-Posting-Date: Wed, 22 Aug 2001 18:10:52 CDT Organization: Raytheon Company Xref: archiver1.google.com comp.lang.ada:12297 Date: 2001-08-22T18:11:08-05:00 List-Id: mop wrote: > 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. > Let's assume you have a two byte unsigned integer. You want to get the two bytes out of it. At least two ways come to mind... [1] The "C" way - see below. [2] An unchecked conversion from a 16 bit integer to a [record or] array of two bytes. and there can certainly be others. As Ted mentioned, you don't mention byte order as being significant. Since you are porting from C however, I'll assume you want to treat the 16 bit value as an integer & get the "low byte" to refer to the least significant 8 bits - no matter what machine you run this on. > > 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; I guess I can assume... #define LOBYTE(Value) (Value&0xff) #define HIBYTE(Value) (Value >>8) if Value is unsigned, or if Value might be signed... #define HIBYTE(Value) ((Value >>8)&0xff) The "C" way in Ada would be to do the same arithmetic in a function. In Ada 95, modular types work great on this. If you think you have a stupid optimizer - use pragma Inline to expand it in line. Yes, it is ten lines of text instead of two, but in this case, GNAT will generate pretty much the same code as gcc will do for C. I'll leave the unchecked conversion as an exercise. I don't recommend it due to the byte order problem. Also, you generally use Ada to use strong typing, not get away from it. --Mark