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,87fc78f2f4541d9 X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: bit manipulation Date: 1999/04/04 Message-ID: #1/1 X-Deja-AN: 462515820 References: <37072A45.2B3BCE90@home.com> NNTP-Posting-Date: Sun, 04 Apr 1999 01:43:59 PDT Newsgroups: comp.lang.ada Date: 1999-04-04T00:00:00+00:00 List-Id: Jack Chow writes: > Can anyone tell me how to do bit manipulation such as bitwise-and and > bitwise or? For modular types, of the form type T is mod 256; -- or whatever modulus is req'd then bitwise "and" and "or" are provided as primitive operations: O1, O2 : T; begin O3 := O1 and O2; O4 := O2 or O3; You can also do and'ing and or'ing of boolean arrays: type Bit_Array is array (Positive range 0 .. 7) of Boolean; for Bit_Array'Size use 8; pragma Pack (Bit_Array); O1, O2 : Bit_Array; begin O3 := O1 and O2; O4 := O2 or O3; Realize that there's often a higher-level way to accomplish a goal in Ada than in C. For example, you can declare a record and specify the location of the components: type RT is record A : Integer range 0 .. 3; B : Integer range 0 .. 15; C : Integer range 0 .. 3; end record; for RT use record A at 0 range 0 .. 1; B at 0 range 2 .. 5; C at 0 range 6 .. 7; end record; for RT'Size use 8; O : RT; begin O.A := 1; O.B := 2; O.C := 0; No bit-level manipulation of the fields is required. You can also use the bit-manipulation facilities in the package Interfaces, described in Annex B of your RM. There's an online RM at the Ada home.