SQL Server Central is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

Bitmap an Integer Value

By Lee Dise, 2003/03/09

Total article views: 36 | Views in the last 30 days: 1

Do you hate using bitwise operands?  I do, a lot.  I wrote the following function to try to minimize the need for using them.  When testing 'status' variables in the 'sysobjects' table, for example, I decided there just had to be an easier way to see if bit 31 is set than asking if STATUS & 0x40000000  0.

There is now, using the following function:

  IF dbo.f_bitmap (STATUS) LIKE '_1%'

The function accepts an integer (INT) value and returns a 32-char string consisting of '1's and '0's, representing (from left to right) the high order bit (32) and low order bit (1) settings of the integer.

Example:  Determine if bit 19 of an integer variable is set.

  IF RIGHT (dbo.f_bitmap (@integer), 19) LIKE '1%'
    PRINT 'BIT 19 is set!'
  ELSE
    PRINT 'BIT 19 is not set'


By Lee Dise, 2003/03/09

Total article views: 36 | Views in the last 30 days: 1
Your response
 
 
Related tags

T-SQL Aids    
 
Already registered?  

Free registration required

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Register

E-mail address:
Password:
Password (confirm):

  

Subscriptions

We ask you to register on the site and subscribe to our newsletters. Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

We ask that you give the newsletter a try for a week. Over 200,000 SQL Server Professionals a day find it entertaining and useful. If not, you are welcome to unsubscribe at anytime.

Steve Jones
Editor, SQLServerCentral.com