comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <sb463ba@l1-hrz.uni-duisburg.de>
Subject: Re: Newbie question: How does one do bit manipulation in Ada?
Date: Tue, 23 Dec 2003 03:01:12 +0000 (UTC)
Date: 2003-12-23T03:01:12+00:00	[thread overview]
Message-ID: <bs8b5o$3h1$1@a1-hrz.uni-duisburg.de> (raw)
In-Reply-To: MPG.1a516ba5b76b5bee989684@news.sover.net

Peter C. Chapin <pchapin@sover.net> 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



  reply	other threads:[~2003-12-23  3:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-23  1:58 Newbie question: How does one do bit manipulation in Ada? Peter C. Chapin
2003-12-23  3:01 ` Georg Bauhaus [this message]
2003-12-23  3:23   ` Peter C. Chapin
2003-12-23  3:36     ` tmoran
2003-12-23  3:33 ` Steve
2003-12-23  9:09 ` Stephen Leake
2003-12-28 13:20   ` Peter C. Chapin
2003-12-28 18:40     ` Robert I. Eachus
2003-12-29  2:57       ` Peter C. Chapin
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox