Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Question of the Day for 20 Apr 2007 Expand / Collapse
Author
Message
Posted Monday, April 9, 2007 12:05 PM
SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Friday, May 18, 2007 3:36 PM
Points: 10,039, Visits: 1
Comments posted to this topic are about the Question of the Day for 20 Apr 2007 posted at http://www.sqlservercentral.com/testcenter/qod.asp?QuestionID=1011.
Post #356933
Posted Thursday, April 19, 2007 10:25 PM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Wednesday, January 5, 2011 9:32 AM
Points: 694, Visits: 89
The explanation says "This returns a 5...", when in fact the rest of the explanation correctly states that it returns 7.




Rick
townsends.ca
Post #359853
Posted Friday, April 20, 2007 12:10 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 2:32 PM
Points: 6,128, Visits: 8,393

The question is okay (though I'd personally prefer to ignore the bitwise operators - too much people with a string backgroun in procedurall programming and a weak level of DBMS skill will want to use them).

But I really don't understand why this question is in the category "Design and Theory". Clearly, it should be in the "T-SQL" category, right?




Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #359866
Posted Friday, April 20, 2007 9:03 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, November 1, 2012 1:18 PM
Points: 110, Visits: 261
I'm trying to visualize a life of bitmasks without bitwise operators. I just had to disable bit 1 on a bunch of rows, and then later reenable bit 1. How would you propose doing this without bitwise operators? With them, it was a snap.

If you would suggest changing the schema, that doesn't work for me. I'm dealing with an off the shelf forum application that would be a ton of work to change the database schema for.
Post #360109
Posted Sunday, April 22, 2007 3:29 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 2:32 PM
Points: 6,128, Visits: 8,393

Hi Adrian,

Try to visualize a life without bitmasks instead.....

Remember the rules for first normal form - every column should only hold atomic values. Clearly, a bit mask violates that rule. If you want to store 8 yes/no values, use 8 columns instead. Define them as bit, if you must (I am not as opposed to the bit datatype as some, but not a big supporter either), and SQL Server will still use only 1 byte to store them. Or store them as CHAR(1) with a CHECK constraint to limit the population to 'Y' of 'N', and gain a lot of clarity at the price a mere 7 extra bytes.




Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #360153
Posted Monday, April 23, 2007 5:16 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, June 17, 2007 9:43 AM
Points: 5, Visits: 1

What are some instances where a bitmask would be useful?

I've been programming for a while now and never really understood their purpose.

Thanks!

Bonnie

Post #360415
Posted Tuesday, April 24, 2007 1:26 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 2:32 PM
Points: 6,128, Visits: 8,393

Hi Bonnie,

Usage of bitmasks was very common and useful up until the seventies, when memory footprint off applications and data came at a premium. If you have to run a program on your home computer with only 32 KB (yes, KILObytes) of memory -half of which was reserved for video memory, keyboard memory, and firmware-, you get to appreciate the value of combining multiple values in a single bytes. And when data has to be stored on a casette recorder with a recording andd playback speed of 300 bits per second, you get to apppreciate the savings even more.

Same for professional development. Those computers often had a whopping 64 kB to their disposal - still good reason to save a few bytes. Storage was on floppy disks, or, for the lucky, on hard disks. One of the earliest hard disk bragged a storage capacity of 5 MB, and came at a price of $ 50,000. Try telling your boss: "The good news is, I decomposed the bit mask in the main file for orders into seperate fields; the bad news is, we need to add a second 5 MB hard disk..."

In modern computer development, bit masks are still used quite often in low-level languages like assembly language, or C. These languages are commonly used for the most performance-critical bits of applications, and since many processors have instructions in their instruction sets for handling bit masks, using bit masks can yield a performance boost.

But in modern third-and-higher generation languages, bit masks have no place at all. And in databases, they should be outright forbidden.




Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #360450
Posted Tuesday, April 24, 2007 8:36 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, November 1, 2012 1:18 PM
Points: 110, Visits: 261
Hugo,
It sounds like you have the luxury of getting to define your own database schema. In the small company that I work for, the database guy (yours truly) has to support integration of any other software we need that uses the DB so bitmasks are a fact of life.
Post #360583
Posted Tuesday, April 24, 2007 9:07 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 2:32 PM
Points: 6,128, Visits: 8,393

Hi Adrian,

Sometimes I do, sometimes I don't have that luxury. I am well aware of how much some third-party DBs suck, and how awful it can be to be stuck with them.

That makes knowledge of what bitmasks are and how they can be operated a Good Thing for those in a similar position as you currently are - but it still doesn't make it right to advertise the use of bitmasks as if they are a Good Thing in themselves.

(Note - I don't think that the QOTD actually "advertises" the use of bitmasks, but it does teach people about them without the "don't do this unless forced to by crappy third-party software" disclaimer that I think ought to be attached here).




Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #360594
Posted Tuesday, April 24, 2007 5:58 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, June 17, 2007 9:43 AM
Points: 5, Visits: 1

Hugo,

Thanks for the quick response and the practical advice!

I thought I may have been missing out on a good shortcut, but I will stay away from them.

Bonnie

Post #360731
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse