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

Home -> Community -> Usenet -> c.d.o.misc -> Re: decimal to binary masks

Re: decimal to binary masks

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Wed, 09 Feb 2000 08:01:16 -0500
Message-ID: <r2p2asshfmlubdom1v2jkkoc53c779vgrv@4ax.com>


A copy of this was sent to spectre_at_hkstar.com (Steve A) (if that email address didn't require changing) On Wed, 9 Feb 2000 12:16:04 +0800, you wrote:

>Hi,
>I want to test for a given bit being set.
>for example a number field being used as flag storage.
>0=no lock
>1=invoiced_locked
>2=shipping_locked
>4=packing_locked
>etc
>
>if bitset(flag,2)
>then
>.....
>else
>XXXXX
>endif
>
>I don't want to have to use UTL_RAW, since it seems to only work on
>varchar2 & rawtypes
>
>any routines out there
>
>
>steve

bitand()

  1* select rownum, bitand( 1234, power(2,rownum-1) )+0, power(2,rownum-1) from all_users where rownum < 32
ops$tkyte_at_8i> /

    ROWNUM BITAND(1234,POWER(2,ROWNUM-1))+0 POWER(2,ROWNUM-1)

---------- -------------------------------- -----------------
         1                                0                 1
         2                                2                 2
         3                                0                 4
         4                                0                 8
         5                               16                16
         6                                0                32
         7                               64                64
         8                              128               128
         9                                0               256
        10                                0               512
        11                             1024              1024
        12                                0              2048
        13                                0              4096
        14                                0              8192
        15                                0             16384
        16                                0             32768
        17                                0             65536
        18                                0            131072
        19                                0            262144
        20                                0            524288
        21                                0           1048576
        22                                0           2097152
        23                                0           4194304
        24                                0           8388608
        25                                0          16777216
        26                                0          33554432
        27                                0          67108864
        28                                0         134217728
        29                                0         268435456
        30                                0         536870912
        31                                0        1073741824


The "+0" part is to let sqlplus believe this is a number, otherwise it believes it is a RAW and won't print it.

--
See http://osi.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'... Current article is "Part I of V, Autonomous Transactions" updated June 21'st  

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 Wed Feb 09 2000 - 07:01:16 CST

Original text of this message

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