Monday, April 10, 2017

java and SQL: Check if a binary number contains certain value

Below are some examples of binary numbers

Decimal format                   Binary format
2                                        00000010
16                                      00010000
18                                      00010010


In Java the operation to test if a binary number contains certain value is "&". For example,

             if ((theNumber & 4) == 4) {
                     . . . . . .
             }

             System.out.println((16 & 2) == 2);  The output is false;
             System.out.println((18 & 2) == 2); The output is true;

In SQL the operation to test if a binary number contains certain value is "bitand". For example,

             select * from Fruit where (bitand (criteria, 8) = 8);
---------------------------------------------------------------------------------------------------------------

                        
If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

No comments:

Post a Comment