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: