Microsoft
Software
Hardware
Network
Question : How do I count the number of set flags in a bitmask?
I know how to use bitwise operators to determine whether a particular bit is set or not. eg: to check if the third bit is set I might say (in psuedo code)
if myBitMask & 4 = 4 then TRUE
however, I have a bitmask of 2,000 bits, and i want count how many are set (the set bits represent a bad event occured, and i want to count how many bad events occurred in total.
eg:
00001000011100000001000000
100001 should be "7"
i.e in pseudo code: countofSetFlags(myBitMask)
I'm hoping to do this efficiently. I'll be querying over a million rows,
Thanks !!!
Paul
Answer : How do I count the number of set flags in a bitmask?
what data type is the field for the bitmask?
if it is varchar, just do this:
len(replace(yourfield, '0',''))
if it's not varchar, just cast it to varchar, and apply the above expression
Random Solutions
Can access 2007 runtime accdr database open an Access 2007 accdb database in runtime only environment?
Trying to reconnect a deleted exchange mailbox into an existing user account
Update from SQL Query
Reporting Services Configuration Error
Inserting picture's from a url into MS SQL Server 2008
flickering in dialog controls
invalid case exception occurred, specified cast not valid.
stop error 0x000000d1 (0x00000000, 0x00000002, 0x00000000, 0x00000000) DRIVER_IRQL_NOT_LESS_OR_EQ<wbr />UAL
Parallels Workstation
Combo Box Events