Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Converting INT Values to HEX

Author  Topic 

avmreddy17
Posting Yak Master

180 Posts

Posted - 2006-04-29 : 13:52:57
Is there any function in SQL Server to convert INT Values to HEX

Ex IF Int Value = 33948700 ,then I shud get HEX Value = 206041C


Thx All for any help

Venu

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-04-29 : 15:27:05
[code]
select [HEX Int] = convert(varbinary(4),33948700)
[/code]
Results:
[code]
HEX Int
----------
0x0206041C

(1 row(s) affected)
[/code]

CODO ERGO SUM
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-05-01 : 10:01:26
what's with shud?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

avmreddy17
Posting Yak Master

180 Posts

Posted - 2006-05-03 : 14:56:24
How to get first four characters from the Varbinary field

I have this column of varbinary type and its values is 0x24000001.
I want to get 0x24 from the above value because I need to convert that to an integer.

Any ideas

Thx
Venu
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-05-03 : 16:10:09
[code]
select First_2 = substring(0x24000001,1,2)

Results:

First_2
-------
0x2400

(1 row(s) affected)
[/code]



CODO ERGO SUM
Go to Top of Page

PSamsig
Constraint Violating Yak Guru

384 Posts

Posted - 2006-05-04 : 01:40:16
Please dont tell me you ended up storing your int in a varbinary field, Im pretty sure the suggestion for varbinary was only for presentation purposes. It is unwise to store it like that and even worse to do 'calculations´ on them like this afterwards.
If you have an in with the value 0x24000001 (a.k.a. 603979777) then just devide it with 0x1000000 (a.k.a. 16777216) and you will get 0x24 (a.k.a. 36). You can see for your self with:

SELECT CONVERT(varbinary(1),603979777/16777216), CONVERT(varbinary(1),0x24000001/0x1000000)

Numbers are numbers, and I adwise to keep them like that.



--
This one's tricky. You have to use calculus and imaginary numbers for this. You know, eleventeen, thirty-twelve and all those.
Go to Top of Page

avmreddy17
Posting Yak Master

180 Posts

Posted - 2006-05-04 : 15:57:29
Thanks Guys for all the help
Go to Top of Page

avmreddy17
Posting Yak Master

180 Posts

Posted - 2006-05-05 : 11:47:33
RosID1 RosID2
67108865 33884956
67108865 33885211
67108865 33885212
67108865 33947907
67108865 33947921
67108865 33947922


The integer values in the RosID1 and RosID2 columns are actually the hex values.
The First Byte of the RosID1 Column represents a threadID and the other three bytes
represents a Seq Number. When I copy these values to the destination tables
I have to change the first byte to a new ThreadID which I will geting as an Input
parameter to the Stored Proc as integer. Also I have to get the max seqNumber from the
destination table's ROSID1 Column for the ThreadID.

what is a best way to do this. Is there a set bases solution to it or we have to use
a CURSOR
Go to Top of Page
   

- Advertisement -