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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Converting hex to int

Author  Topic 

allyanne
Starting Member

18 Posts

Posted - 2001-03-06 : 10:47:33
I need some help converting hex values. Here's my problem: I have a field that stores a hex value as a varchar (don't ask why). I need to convert this to its integer value.

Say for example the value is 3f, which should convert to 63. The following statement works:

select convert(int, 0x3f)

But the problem is that the field is varchar. I get an error if I try

select convert(int, '0x3f')

I get an incorrect result of 48 if I do this:

select convert(int, convert(binary(1), '0x3f')

And the following...

select convert(int, convert(binary(1), '3f')

... gives me a result of 51!

Does anyone have any ideas??


   

- Advertisement -