Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Bitwise operator in PL/SQL
Haresh,
I had a similar requirement. I needed to examine the value of a certain bit in
a
number. I do not think there is an operator to do this so I wrote my own
as follows:
CREATE OR REPLACE FUNCTION bit_value(num IN INTEGER,
bit IN INTEGER) RETURN INTEGER AS bval INTEGER; BEGIN bval := num; FOR i IN 1 .. (bit-1) LOOP bval := TRUNC((bval/2),0); END LOOP; RETURN MOD(bval,2);
bitval INTEGER;
bitval := bit_value(num, 3);
I hope this helps;
Haresh Assumal wrote:
> Hi,
> Does anyone know if there is a bitwise operator in PL/SQL. I need to
> compare bits in a number field, Eg if i=3 (101 binary) and j=1 then i AND j
> = 1, if k=2 (010 binary) then i AND k = 0.
> What I am looking for is the bitwise AND operator.
>
> Thanks,
> Haresh
-- ************************* Gary Smith CERN, Geneva, Switzerland Email: Gary.Smith_at_cern.ch Tel: +41 22 7678944 *************************Received on Thu Oct 30 1997 - 00:00:00 CST
![]() |
![]() |