If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Bitwise operation in DB2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-22-04, 13:46
ubs ubs is offline
Registered User
 
Join Date: Dec 2004
Posts: 2
Question Bitwise operation in DB2

Assume that TABLE.STATUS = 01010010 and we want to test if a particular bit ( let us say bit 2 xxxxxx1x) is true or false;

Can you do bit operations such as the following:

SELECT * FROM TABLE A WHERE A.STATUS & (0x20) == TRUE;

In DB2 can we can do bit manipulations similar to the above?
Reply With Quote
  #2 (permalink)  
Old 12-22-04, 14:22
auser auser is offline
Registered User
 
Join Date: Dec 2004
Posts: 1
how to check the bit status in db2

Hi,

If you want to test if the second bit of a number XXXX1X is set, you can test like

select from table.status where table.status mod 2 = 0.

If testing for second bit, where table.status mod 4 = 0, and so on for nth bit

use mod 2 to the power of n-1.
Reply With Quote
  #3 (permalink)  
Old 12-22-04, 16:02
ubs ubs is offline
Registered User
 
Join Date: Dec 2004
Posts: 2
Does not work in all situations

I tried that but it does not work in all cases.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On