Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2004
    Posts
    2

    Question Unanswered: 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?

  2. #2
    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.

  3. #3
    Join Date
    Dec 2004
    Posts
    2

    Does not work in all situations

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •