Go Back   EQEmulator Home > EQEmulator Forums > General > General::General Discussion

General::General Discussion General discussion about EverQuest(tm), EQEMu, and related topics.
Do not post support topics here.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 04-05-2007, 02:37 PM
ndnet
Hill Giant
 
Join Date: Oct 2003
Posts: 105
Default

SQL supports bitwise operators, such as & | ^ ~ etc.

If you have a set of numbers and you want to match them via bitmasks, it's easy to use the bitwise operators to do so.

Example table "bittest" with column "mask" that has some ints: (btw trying to format these sucks)
Code:
     +------+
     | mask |
     +------+
     | 5 |
     | 2 |
     | 3 |
     | 8 |
     | 4 |
     +------+
Now you have a bitmask 0100 which is the number 4. You want all numbers that have the bit set to 1.

Code:
mysql> SELECT * FROM `bittest` WHERE `mask` & 4;
     +------+
     | mask |
     +------+
     | 5 | < -- 0101
     | 4 | < -- 0100
     +------+

Now with the same mask 0100, you want all numbers where that bit is 0.

Code:
mysql> SELECT * FROM `bittest` WHERE NOT `mask` & 4;
     +------+
     | mask |
     +------+
     | 2 | < -- 0010
     | 3 | < -- 0011
     | 8 | < -- 1000
     +------+

And so forth~
Reply With Quote
 

Thread Tools
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 On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 12:19 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3