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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,70ff6d6e203062f6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-22 19:01:13 PST Path: archiver1.google.com!news2.google.com!fu-berlin.de!cs.tu-berlin.de!uni-duisburg.de!not-for-mail From: Georg Bauhaus Newsgroups: comp.lang.ada Subject: Re: Newbie question: How does one do bit manipulation in Ada? Date: Tue, 23 Dec 2003 03:01:12 +0000 (UTC) Organization: GMUGHDU Message-ID: References: NNTP-Posting-Host: l1-hrz.uni-duisburg.de X-Trace: a1-hrz.uni-duisburg.de 1072148472 3617 134.91.1.34 (23 Dec 2003 03:01:12 GMT) X-Complaints-To: usenet@news.uni-duisburg.de NNTP-Posting-Date: Tue, 23 Dec 2003 03:01:12 +0000 (UTC) User-Agent: tin/1.5.8-20010221 ("Blue Water") (UNIX) (HP-UX/B.11.00 (9000/800)) Xref: archiver1.google.com comp.lang.ada:3731 Date: 2003-12-23T03:01:12+00:00 List-Id: Peter C. Chapin wrote: : Anyway, I have a need to do some bit manipulations in one of my : programs. In particular I want to invert certain bits in a number : (integer). I'm used to doing this with a bitwise XOR operator (C/C++) so : I looked around for some kind of equivalent in Ada but I didn't find : anything in package Standard or in any of the "usual" library packages. : Am I missing something or am I just thinking about this wrong? xor is available for Boolean types, modular types, and one-dimensional arrays of Booleans, as well as for (Wide_)Character_Sets. Some signed and modular integer types are predefined in package Interfaces. If you cannot use the modular variant of integers, but you know that some integers values in question are bitwise represented like modular values, you could do an unchecked_conversion. In addition, package Interfaces has Shift_Left/Right, Shift_Right_Arithmentic, and Rotate_Left/Right. It is also possible to use representation clauses and assign names to bits or groups of bits that are components of a record (and possibly again do unchecked_conversions if needed). -- Georg