posted on Wednesday, January 26, 2005 7:54 PM by amachanic

Correction on bitmask handling

In the article on handling bitmasks I posted the other day, I made a fatal error in the splitBitmask function. The function treated the low byte as the first byte, instead of the high byte. Therefore:

0x01 != 0x0001

... and that is not good!

So here's a corrected version that fixes the problem:

CREATE FUNCTION dbo.splitBitmask
(
	@Bitmask VARBINARY(4096)
)
RETURNS TABLE
AS
RETURN
(
	SELECT Number
	FROM BitmaskNumbers
	WHERE (SUBSTRING(@Bitmask, DATALENGTH(@Bitmask) - Byte + 1, 1) & BitValue) = BitValue
		AND Byte <= DATALENGTH(@Bitmask)
)
GO

More to come soon... Bit shifting, logical operators, and other fun ways to annoy this guy:

Comments

# Correction on bitmask handling @ Thursday, July 13, 2006 12:26 AM

Originally posted here.

In the article on handling bitmasks I posted the other day, I made a fatal...

Anonymous

# Bitmask Handling, part 2: Bitmask reconstitution @ Thursday, July 13, 2006 12:27 AM

Originally posted here.

Posting the first part
of my series on bitmasks (yes, this is now officially...

Anonymous

# Bitmask Handling, part 2: Bitmask reconstitution @ Monday, January 08, 2007 2:35 PM

Originally posted here . Posting the first part of my series on bitmasks (yes, this is now officially

Anonymous

# Correction on bitmask handling @ Monday, January 08, 2007 2:35 PM

Originally posted here . In the article on handling bitmasks I posted the other day, I made a fatal error

Anonymous