From: Mats Weber <matsw@mail.com>
Subject: Re: Bit Manipulations
Date: 1999/12/21
Date: 1999-12-21T12:19:34+00:00 [thread overview]
Message-ID: <385F7055.7450E3A7@mail.com> (raw)
In-Reply-To: B9063F55105FD21189FE0000F8103B5B0216503E@emss35m04.owg.fs.lmco.com
generic
type T is private;
function bitwise_and (left, right : T) return T;
function bitwise_and (left, right : T) return T is
type bit_array_t is array (1 .. T'Size) of Boolean;
pragma Pack (Bit_Array_T);
function to_t is new unchecked_conversion(bit_array_t, t);
function to_bit_Array is new unchecked_conversion(t, bit_array_t);
begin
return to_t(to_bit_array(left) and to_bit_array(right));
end;
Then create "and" operators for the types you need, e.g.:
type my_int is range -34 .. 2222;
function "and" is new bitwise_and(character);
function "and" is new bitwise_and(integer);
function "and" is new bitwise_and(my_int);
> For instance, I get a byte from a hardware port and want to mast off the
> parity bit ( 16#07F#).
>
> I want to do...
>
> char_data := char_data AND 16#07F#
or, simpler:
if character'pos(char_data) > 127 then
char_data := character'val(character'pos(char_data) - 128);
end if;
next prev parent reply other threads:[~1999-12-21 0:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-12-20 0:00 Bit Manipulations Simon, Jb
1999-12-21 0:00 ` Ted Dennison
1999-12-21 0:00 ` Mats Weber [this message]
1999-12-21 0:00 ` tmoran
1999-12-21 0:00 ` Matthew Heaney
1999-12-21 0:00 ` Robert I. Eachus
[not found] <B9063F55105FD21189FE0000F8103B5B0216503E@emss35m04.owg.fs.lmco .com>
1999-12-21 0:00 ` Matthew Heaney
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox