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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,cec65b0a3ccd802d X-Google-Attributes: gid103376,public From: Stephen Leake Subject: Re: Big-endian vs little-endian Date: 1999/02/09 Message-ID: #1/1 X-Deja-AN: 442549404 References: <36B155D2.2E8573BB@wvu.edu> <7982p9$nll$3@plug.news.pipex.net> <36BB9A6E.D472A709@wvu.edu> Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA Newsgroups: comp.lang.ada Date: 1999-02-09T00:00:00+00:00 List-Id: Mike Werner writes: > Here's the relevant data structure: > > type Sys_type is (Zarya, Unity, PMA1, PMA2); > type Subsys_type is (CDH, CT, ECLSS, EPS, GNC, SM); > subtype Desc_type is String(1..256); > subtype Dur_Min_Type is Integer; > subtype Dur_Sec_type is Integer; > type Apm_Rec is > record > Description : Desc_Type; > System : Sys_Type; > Subsystem : Subsys_Type; > Dur_Min : Dur_Min_Type; > Dur_Sec : Dur_Sec_Type; > end record; > > The problematic parts were the Apm_Rec.Dur_Min and the Apm_Rec.Dur_Sec - > all the others read in just fine. You have a byte-endianness problem. System.Bit_Order address a bit-endiannes problem. They are similar, but different. The best Ada solution is to use streams to read the binary file. You have to define your own Integer type (you should do this anyway, to make sure it is the same size as the school's server Integer type!). Then you can define the stream read and write functions to do byte swapping. If you're not up to streams (quite understandable :), you can just use Unchecked_Conversion. Assuming 32 bit integers, do something like: type Network_4_Bytes is record Hi_Byte : Interfaces.Unsigned_8; Byte_3 : Interfaces.Unsigned_8; Byte_2 : Interfaces.Unsigned_8; Low_Byte : Interfaces.Unsigned_8; end record; pragma Pack (Network_4_Bytes); for Network_4_Bytes'size use 32; -- confirm size function To_Network is new Unchecked_conversion (Source => Interfaces.Integer_32, Target => Network_4_Bytes); Of course, to make your code portable to your school computer, you'll have to hide this in a body, and set a compile-time flag to decide whether to swap bytes or not. I define a package Endianness to handle the compile-time flag. Good luck! -- Stephe