dbTalk Databases Forums  

Binary Value Manipulation

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Binary Value Manipulation in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
tfeller
 
Posts: n/a

Default Binary Value Manipulation - 05-01-2007 , 01:26 PM






I would like to drop the leading 0x on a binary value so I can do a
bitwise operation.

Here is simplified code:

select right(0x88186000,8)

I expected to get back 88186000, this was not the case. The command
returned some wierd characters.

Am I missing something?


Reply With Quote
  #2  
Old   
Plamen Ratchev
 
Posts: n/a

Default Re: Binary Value Manipulation - 05-01-2007 , 04:10 PM






The expressions in the bitwise operations are treated as binary numbers, and
one of the expressions can be a binary data type. So, you do not have to
convert your binary value, just use it directly. The results is of data type
integer and you can convert it back to binary. Try this:

SELECT CAST(0x88186000 ^ 2 AS binary(4)),
CAST(0x88186000 | 2 AS binary(4)),
CAST(0x88186000 & 2 AS binary(4))

HTH,

Plamen Ratchev
http://www.SQLStudio.com




Reply With Quote
  #3  
Old   
Hugo Kornelis
 
Posts: n/a

Default Re: Binary Value Manipulation - 05-01-2007 , 04:39 PM



On 1 May 2007 11:26:58 -0700, tfeller wrote:

Quote:
I would like to drop the leading 0x on a binary value so I can do a
bitwise operation.

Here is simplified code:

select right(0x88186000,8)

I expected to get back 88186000, this was not the case. The command
returned some wierd characters.

Am I missing something?
Hi tfeller,

Maybe the functions Peter DeBetta describes will help you to achieve
what you need:
http://sqlblog.com/blogs/peter_debet...varbinary.aspx

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.