Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Bathing in Bit Masks

Author  Topic 

rharmon
Starting Member

41 Posts

Posted - 2002-11-12 : 15:07:59
I'm working on a warehousing project retrieving data from a shrink-wrap solution. A couple of tables in the database have fields that store bit masks of 16 bits in an integer field to represent 16 boolean expressions. I need to migrate these tables to star based schemas, effectively splitting the 16bit field to 16 1 bit fields.

As an example using a 4 bit integer:
Bit 0 (0x01) = tired
Bit 1 (0x02) = morally bankrupt
Bit 2 (0x04) = happy to be here
bit 3 (0x08) = wishing the bad man would to away

and an integer of 13, how do I return

Tired Morally_Bankrupt Happy_to_be_here Go_Away_Bad_Man
----- ---------------- ---------------- ---------------
1 0 1 1



Edited by - rharmon on 11/12/2002 15:10:05

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2002-11-12 : 15:31:10
Something like this:

SELECT
CAST(SIGN(bitmask & 0x01) AS bit) AS "tired",
CAST(SIGN(bitmask & 0x02) AS bit) AS "morally bankrupt",
CAST(SIGN(bitmask & 0x04) AS bit) AS "happy to be here",
CAST(SIGN(bitmask & 0x08) AS bit) AS "wishing the bad man would to away"
FROM (SELECT 13 AS bitmask) a



Go to Top of Page

rharmon
Starting Member

41 Posts

Posted - 2002-11-12 : 16:25:10
outstanding! THANKS!

Go to Top of Page
   

- Advertisement -