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: Bit-Manipulation???

Re: Bit-Manipulation???

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Sun, 20 Jun 1999 13:50:33 GMT
Message-ID: <376df0a4.1640619@newshost.us.oracle.com>


A copy of this was sent to P Jeromel <pjeromel_at_hotmail.com> (if that email address didn't require changing) On Sun, 20 Jun 1999 18:38:30 +0930, you wrote:

>Hi All,
>
>Does anyone know if there are any packages available which allows bit
>manipulation
>on datatypes (preferably NUMBER or REAL)???
>

what kind of bit manipulations?

there is an undocumented 'bitand()' routine you can call.

If you need bitor, this might do it for you:

CREATE OR replace FUNCTION bitor( x IN NUMBER, y IN NUMBER ) RETURN NUMBER   AS

  l_x PLS_INTEGER     DEFAULT x;
  l_y PLS_INTEGER     DEFAULT y;
  l_r PLS_INTEGER     DEFAULT 0;
  l_tmp PLS_INTEGER := 1;

BEGIN
    FOR i IN 1 .. 32 LOOP
        IF ( bitand(l_x,l_tmp) = l_tmp OR bitand(l_y,l_tmp) = l_tmp )
        THEN
            l_r := l_r + l_tmp;
        END IF;
        l_tmp := l_tmp * 2;
        exit when ( l_tmp >= l_x AND l_tmp >= l_y );
    END LOOP;     RETURN l_r;
END;
/

that function is callable from sql as well. both bitand and the above bitor only work with 32bit integers (don't work with abs(numbers) > 2^31)

>I know of the UTL_RAW with it's functions/procedures.
>

>(It's for a small Data Conversion job - so I would rather not write
>something too large to do the job).
>
>Is there anything else out there which comes with 8.0.5 Workgroup
>Server?
>
>Thanks.
>Paul
>

--
See http://govt.us.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'... Current article is "Fine Grained Access Control", added June 8'th  

Thomas Kyte                   tkyte_at_us.oracle.com
Oracle Service Industries     Reston, VA   USA

Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Sun Jun 20 1999 - 08:50:33 CDT

Original text of this message

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