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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,705f377a5e04a446 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!feeder.news-service.com!feeder.news-service.com!feeder2.cambrium.nl!feeder4.cambrium.nl!feed.tweaknews.nl!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Bit operations in Ada (endianness) References: <87wslksmgk.fsf@ludovic-brenta.org> Date: Mon, 02 Jun 2008 19:38:15 +0200 Message-ID: <877id7ka9k.fsf@ludovic-brenta.org> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:c/thOjYqWQ7McIrGGs3mnzHMawI= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: Tele2 X-Trace: DXC=V;I[T7MR@DfQ@8iTl]i3Ll6`Y6aWje^Yj?RBPN0CW2J`]9LCQDYXe7`SOWU?G<`gSlZ>e^=MdYAam Xref: g2news1.google.com comp.lang.ada:529 Date: 2008-06-02T19:38:15+02:00 List-Id: Dennis Hoppe writes: > Hi, > > I have another question regarding litte and big-endian. Is there > any way to declare, that the type > > type Bit_Field is array (Bit_Number) of Boolean; > > is represented by litte or big-endian? Bit_Number is a generic > paremeter (mod <>). I figured out to set the endianness to > record types, but it does not work for the above array type. The arithmetic on modular types does what you need, so the problem only arises when using the bit-array representation. You need to invert the index explicitly on little-endian machines. > I also wonder, if I can query the operating system via Ada, > which endianness it uses. Look at System.Default_Bit_Order. So a solution might look like: generic type Bit_Number is mod <>; package Bit_Fields is type Bit_Field is array (Bit_Number) of Boolean; function Index (N : Bit_Number) return Bit_Number; end Bit_Numbers; with System; package body Bit_Numbers is function Index (N : Bit_Number) return Bit_Number is begin case System.Default_Bit_Order is when System.High_Order_First => return N; when System.Low_Order_First => return Bit_Number'Last - N; end case; end Index; end Bit_Numbers; HTH -- Ludovic Brenta.