Bitmasken in Oracle SQL...


Oracle SQL für Wilde ;-)
I) Ein Bit (newstore) in einer Bitmaske (mask) setzen:

select (mask + newstore) - BitAND(mask, newstore) /*bitor*/
  from
        ( select 9 as mask, 8 as newstore from dual ) /*sampledata*/;

II) Ein Bit (oldstore) aus einer Bitmaske entfernen

select
  case when bitand(mask,oldstore)=0   /* store nicht in maske */
    then mask              /* unveraendert wenn nicht gesetzt */
    else (mask + oldstore) - BitAND(mask,oldstore)*2  /*bitxor*/
  end as newmask
from
 ( select 25 as mask, 8 as oldstore from dual ); /* sampledata*/

oder auch:
                                                                                        
    select bitand( mask,   (-1-oldstore) /* bitnot */  )                            
    as newmask   from  ( select 25 as mask, 8 as oldstore from dual )  ;


Lesbar finde ich es nicht, war aber besser als meine Alternativen.


Kommentare

Beliebte Posts aus diesem Blog

using the birt runtime with spring boot and gradle to generate PDF from a Report Design File

Powershell snippet to send messages to telegram