Results 1 to 7 of 7

Thread: what is a bit mask?

  1. #1
    Hello jackvdbuk's Avatar
    Join Date
    Apr 2006
    Location
    Stratford
    Posts
    2,513
    Thanks
    468
    Thanked
    112 times in 95 posts
    • jackvdbuk's system
      • Motherboard:
      • AbiT IP35-PRO
      • CPU:
      • Intel C2Q Q9550
      • Memory:
      • OCZ Nvidia SLi Edition 4GB (2x2gb) pc2-6400 DDR2
      • Storage:
      • lots of TB
      • Graphics card(s):
      • BFG 8800GTS 512MB
      • PSU:
      • Corsair HX620W
      • Case:
      • Corsair 800D
      • Operating System:
      • Windows 7 Premium x64
      • Monitor(s):
      • Dell 2407WFP
      • Internet:
      • Orange (about 6Mb)

    what is a bit mask?

    had a look online but do not understand it at all anyone care to help??

  2. #2
    Does he need a reason? Funkstar's Avatar
    Join Date
    Aug 2005
    Location
    Aberdeen
    Posts
    19,874
    Thanks
    630
    Thanked
    965 times in 816 posts
    • Funkstar's system
      • Motherboard:
      • Gigabyte EG45M-DS2H
      • CPU:
      • Intel Core2Quad Q9550 (2.83GHz)
      • Memory:
      • 8GB OCZ PC2-6400C5 800MHz Quad Channel
      • Storage:
      • 650GB Western Digital Caviar Blue
      • Graphics card(s):
      • 512MB ATI Radeon HD4550
      • PSU:
      • Antec 350W 80+ Efficient PSU
      • Case:
      • Antec NSK1480 Slim Mini Desktop Case
      • Operating System:
      • Vista Ultimate 64bit
      • Monitor(s):
      • Dell 2407 + 2408 monitors
      • Internet:
      • Zen 8mb
    http://en.wikipedia.org/wiki/Bit_mask

    basically you have some data that is made up of a number of fields. Each of these fields are either True or False. Instead of storing them seperately in a database (for example) you can store them in one binary string.

    You read the binary string out of the DB, you then perform an AND operation on that string with the value you are looking for. If you want to see if the 5th bit in the string is true or flase you do the following:

    100111010 AND 000010000 = 000010000

    In this case the result is equal to the mask you used, meaning that bit is True. To set it to False you do this:

    100111010 AND 111101111 = 100101010

    to set it back to True you do this:

    100111010 OR 000010000 = 100111010

    If you don't care what the value is, you just want to chang eit to the oposite value you use an XOR:

    100111010 XOR 000010000 = 100101010

    that any help to you?


  3. #3
    Hello jackvdbuk's Avatar
    Join Date
    Apr 2006
    Location
    Stratford
    Posts
    2,513
    Thanks
    468
    Thanked
    112 times in 95 posts
    • jackvdbuk's system
      • Motherboard:
      • AbiT IP35-PRO
      • CPU:
      • Intel C2Q Q9550
      • Memory:
      • OCZ Nvidia SLi Edition 4GB (2x2gb) pc2-6400 DDR2
      • Storage:
      • lots of TB
      • Graphics card(s):
      • BFG 8800GTS 512MB
      • PSU:
      • Corsair HX620W
      • Case:
      • Corsair 800D
      • Operating System:
      • Windows 7 Premium x64
      • Monitor(s):
      • Dell 2407WFP
      • Internet:
      • Orange (about 6Mb)
    i sort of get it , but still confused sadly is this a way of representing data?

    i have got to 'state the basic princinples involved in the represtation of data (including Bit masks) within a computer system' i have written bout ascii, bianry, bit maps but i am stuck on bit masks!

  4. #4
    Senior Member charleski's Avatar
    Join Date
    Jul 2006
    Posts
    1,586
    Thanks
    7
    Thanked
    52 times in 45 posts
    Simple data is commonly stored as a set of flags or short bit sequences. I.e. you can store 4 flags and 1 4-bit number in a single byte, then access these data using bit masks to filter out the relevant datum.

    Eg:
    Code:
    FlagA FlagB FlagC FlagD   Number
      1     0     1     1      1011
    then <data byte> AND 10000000 gives you the value of flagA
    So the bit mask specifies which piece of a set of data you want to look at.

  5. #5
    Does he need a reason? Funkstar's Avatar
    Join Date
    Aug 2005
    Location
    Aberdeen
    Posts
    19,874
    Thanks
    630
    Thanked
    965 times in 816 posts
    • Funkstar's system
      • Motherboard:
      • Gigabyte EG45M-DS2H
      • CPU:
      • Intel Core2Quad Q9550 (2.83GHz)
      • Memory:
      • 8GB OCZ PC2-6400C5 800MHz Quad Channel
      • Storage:
      • 650GB Western Digital Caviar Blue
      • Graphics card(s):
      • 512MB ATI Radeon HD4550
      • PSU:
      • Antec 350W 80+ Efficient PSU
      • Case:
      • Antec NSK1480 Slim Mini Desktop Case
      • Operating System:
      • Vista Ultimate 64bit
      • Monitor(s):
      • Dell 2407 + 2408 monitors
      • Internet:
      • Zen 8mb
    It is quite complex, took me ages to get my head round it when a friend was trying to explain it to me a few years back. I was going to be using it in a database i was building at the time. Instead of having 20 (or so) True/False fields in a table, i would have a single "settings" field that could be an integer (number) field. If you treat this number as a string of binary, which is all it is, with each binary position as a unique piece of True/False data, you are able to store everything very efficiently. Another upside of this is you are only reading or storing to one field in a DB, so accesses could, in theory, be quicker. Of course you do have to do more to the field to decode the data, but that will be far quicker than pulling the data from the DB.

    T is True, F is False, Fx is the Field name

    Code:
     F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 |
    ---------------------------------------------
      1 |  0 |  0 |  1 |  1 |  1 |  0 |  1 |  0 |
    
    =
    
     F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 |
    ---------------------------------------------
      T |  F |  F |  T |  T |  T |  F |  T |  F |
    
    =
    
    | Settings  |
    -------------
    | 100111010 | (in binary) 
    
    =
    
    | Settings  |
    -------------
    | 314       | (in decimal)

  6. #6
    Moderator DavidM's Avatar
    Join Date
    Jan 2005
    Posts
    8,764
    Thanks
    789
    Thanked
    249 times in 232 posts
    Either useful for software sprite handling (now *that's* been a long while since i've done that!) or as Funkstar says - for masking out values for checks... very handy in bit based operations (I seem to remember using this method for a house alarm project for college )

  7. #7
    Does he need a reason? Funkstar's Avatar
    Join Date
    Aug 2005
    Location
    Aberdeen
    Posts
    19,874
    Thanks
    630
    Thanked
    965 times in 816 posts
    • Funkstar's system
      • Motherboard:
      • Gigabyte EG45M-DS2H
      • CPU:
      • Intel Core2Quad Q9550 (2.83GHz)
      • Memory:
      • 8GB OCZ PC2-6400C5 800MHz Quad Channel
      • Storage:
      • 650GB Western Digital Caviar Blue
      • Graphics card(s):
      • 512MB ATI Radeon HD4550
      • PSU:
      • Antec 350W 80+ Efficient PSU
      • Case:
      • Antec NSK1480 Slim Mini Desktop Case
      • Operating System:
      • Vista Ultimate 64bit
      • Monitor(s):
      • Dell 2407 + 2408 monitors
      • Internet:
      • Zen 8mb
    never done any sprite handling. good to know i wasn't the only one that started a house alarm project though

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 9
    Last Post: 07-09-2005, 09:47 AM
  2. Bit torrent crashing
    By dkmech in forum Help! Quick Relief From Tech Headaches
    Replies: 17
    Last Post: 17-07-2004, 01:29 PM
  3. When is 64 bit windows due?
    By wedge22 in forum Software
    Replies: 15
    Last Post: 18-06-2004, 02:45 PM
  4. Nintendo Boss a tad bit annoyed...
    By Devilbod in forum Gaming
    Replies: 15
    Last Post: 14-06-2004, 06:01 PM
  5. a teeny bit o' help...please?
    By shiato storm in forum General Discussion
    Replies: 11
    Last Post: 25-05-2004, 07:19 PM

Posting Permissions

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