473,320 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Binary Value Manipulation

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?

May 1 '07 #1
3 4848
tfeller <To********@gmail.comwrote in news:1178044017.983887.201130
@o5g2000hsb.googlegroups.com:
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?
What do you get back from SELECT 0x88186000 ?

I don't expect it will be 0x88186000

Try SELECT CAST(0x41424344 as varchar) and you should get back ABCD

The _representation_ (note emphasis) of a binary value _in T-SQL_ is a
sequence of characters that begin with 0x - but the 0x does not form part
of the _actual binary value_, any more than the starting and ending quotes
form part of a character value.

May 1 '07 #2
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

May 1 '07 #3
On 1 May 2007 11:26:58 -0700, tfeller wrote:
>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
May 1 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jaakko Holster | last post by:
Lets run following code: ------- snip ------ class Perm { static $read = bindec('001'); static $write = bindec('010'); static $delete = bindec('100'); }
2
by: lastusernameleft | last post by:
What is the easiest .net method to read a REG_BINARY value from the registry? I'm using a ManagementClass from the System.Management namespace and can retrieve string values using...
19
by: jeff | last post by:
how do you convert form byte to Int32 while retaining the binary value of the byte array
7
by: Golan | last post by:
Hi, I need to convert a Binary value to Decimal. I've been told that the value is an unsigned one. How can I do this? I use memcpy into an unsigned char variable, but when I print the value I got...
3
by: ForestDemon | last post by:
i'm able to use the GetValue() function for string usage/manipulation, but i can't figure out how to read/write a binary value to/from a key. any help is greatly appreciated...thanks folks!
2
by: yxq | last post by:
There are 8 bytes binary value stored date and time in Registry. 84 8B D7 DF 8B 28 C5 01 I want to convert the binary value to date using VB.NET. Dim a As FILETIME a.dwHighDateTime = 29698187...
6
by: Shawn B. | last post by:
Greetings, I've been up and down google on this one and clearly I don't know what search terms to use because I can't locate how to do this for binary values (or hex)... in C#, we can specify...
1
by: Simon | last post by:
Dear reader, In a Make-Table query the TickBox from the master table transfers in to a binary value in the new table. How can I force the Make-table query to keep the TickBox in the new...
12
by: waterdriven | last post by:
Hello; I am a newbie. A homework assignment was assigned and I am having trouble getting started. The assignment reads: Write a program to print out the binary value of a 16 bit number.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.