Bit-Twiddling in SQL

Posted by Mike C on SQL Blog See other posts from SQL Blog or by Mike C
Published on Sun, 04 Apr 2010 03:40:00 GMT Indexed on 2010/04/04 3:53 UTC
Read the original article Hit count: 498

Someone posted a question to the SQL Server forum the other day asking how to count runs of zero bits in an integer using SQL. Basically the poster wanted to know how to efficiently determine the longest contiguous string of zero-bits (known as a run of bits) in any given 32-bit integer. Here are a couple of examples to demonstrate the idea: Decimal = Binary = Zero Run 999,999,999 decimal = 00 111011 1 00 11010 11 00 1 00 1 11111111 binary = 2 contiguous zero bits 666,666,666 decimal = 00100111 10111100...(read more)

© SQL Blog or respective owner

Related posts about bit twiddling

Related posts about code