From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: bit operations on integers
Date: 1999/05/03
Date: 1999-05-03T00:00:00+00:00 [thread overview]
Message-ID: <7gkr2g$k5g@hobbes.crc.com> (raw)
In-Reply-To: 7gkhr7$5kr$1@nnrp1.dejanews.com
phadreus@iname.com wrote in message <7gkhr7$5kr$1@nnrp1.dejanews.com>...
>
>
>How do I test, set, and clear individual bits in an integer
>in Ada 83?
>
How about:
package Bit_Ops is
function Test
(Item : Integer;
N : Natural)
return Boolean;
procedure Set
(Item : in out Integer;
N : Natural);
procedure Clear
(Item : in out Integer;
N : Natural);
end Bit_Ops;
package body Bit_Ops is
type Bit_Array is
array (Natural range 0 .. Integer'Size - 1)
of Boolean;
pragma Pack (Bit_Array);
-----------
-- Clear --
-----------
procedure Clear
(Item : in out Integer;
N : Natural)
is
Bits : Bit_Array;
for Bits use at Item'Address;
begin
Bits (N) := False;
end Clear;
---------
-- Set --
---------
procedure Set
(Item : in out Integer;
N : Natural)
is
Bits : Bit_Array;
for Bits use at Item'Address;
begin
Bits (N) := True;
end Set;
----------
-- Test --
----------
function Test
(Item : Integer;
N : Natural)
return Boolean
is
Bits : Bit_Array;
for Bits use at Item'Address;
begin
return Bits (N);
end Test;
end Bit_Ops;
next prev parent reply other threads:[~1999-05-03 0:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-05-03 0:00 bit operations on integers phadreus
1999-05-03 0:00 ` David C. Hoos, Sr. [this message]
1999-05-03 0:00 ` Keith Thompson
1999-05-03 0:00 ` Matthew Heaney
1999-05-03 0:00 ` dennison
1999-05-03 0:00 ` Jerry Petrey
1999-05-04 0:00 ` Vincent P. Amiot
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox