Thursday, March 8, 2012

Convert string to hex to int

My table has some hexadecimal data but stored as string. I want to
convert this to hex and then to int. How do I do this?
Data in my table:
139D5
6374
63B2
620B
ABC7
6391
6FA6
604A
139D6
This should be ideally
0x139D5
0x6374
0x63B2
0x620B
0xABC7
0x6391
0x6FA6
0x604A
0x139D6
How do I convert 139D5 to 0x139D5 so that I can cast it as an integer?
declare @.a varchar (1000)
set @.a='139D5'
select cast(cast (@.a as varbinary) as int)
select cast (0x 139D5 as int)
These two stmts give different results. Only the second one is correct.
Please help.
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!Why did you save hexadecimal value to string? Instead you can directly
store it as integer
Madhivanan|||Hi
Check out this previous post:
http://tinyurl.com/6syea
John
"male hit" wrote:

> My table has some hexadecimal data but stored as string. I want to
> convert this to hex and then to int. How do I do this?
> Data in my table:
> 139D5
> 6374
> 63B2
> 620B
> ABC7
> 6391
> 6FA6
> 604A
> 139D6
> This should be ideally
> 0x139D5
> 0x6374
> 0x63B2
> 0x620B
> 0xABC7
> 0x6391
> 0x6FA6
> 0x604A
> 0x139D6
> How do I convert 139D5 to 0x139D5 so that I can cast it as an integer?
> declare @.a varchar (1000)
> set @.a='139D5'
> select cast(cast (@.a as varbinary) as int)
> select cast (0x 139D5 as int)
> These two stmts give different results. Only the second one is correct.
> Please help.
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!
>

No comments:

Post a Comment