Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Bitwise operator in PL/SQL

Re: Bitwise operator in PL/SQL

From: Amos Elberg <aelberg_at_ziplink.net>
Date: 1997/10/30
Message-ID: <34591F9D.13142479@ziplink.net>#1/1

I also have a need for bitwise operators, specifically both OR and AND. I spoke to someone in tech support a month or two back who suggested trying bit_and() and bit_or(), but neither worked. If you do find a good solution to the problem, can you let the rest of us know about it?
-Amos

Gary SMITH wrote:

> 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);
> END;
>
> It works like this. If you want to find out the bit value of say bit 3 in a
> number
> then you can write code like this:
>
> 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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US