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
 Transact-SQL (2000)
 SQL 6.5 and Hexadecimals...

Author  Topic 

BAz
Starting Member

7 Posts

Posted - 2002-01-15 : 06:03:34
DOn't know if i got the right group here, but what the hell...

I'm busy playing around with hexadecimal values. The goal is to convert an int to a binary, and then to a string.

I read in my trusty SQL 6.5 Hold-My-Hand-I'm-A-Beginner book that I can use the following statement :
SELECT CONVERT (BINARY(4),123455)

and then I should get an 0x<whatever> representation.
When I run this query, I see <binary>.

O.K., so now I'm a bit lost, 'cos that's just what happens to me when something in the book doesn't work for me...

can anybody understand what I'm asking, and if so, can one of those people help me?

Thanx

BAz


chadmat
The Chadinator

1974 Posts

Posted - 2002-01-15 : 13:14:54
How about this:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q104829

HTH
-Chad

Go to Top of Page

BAz
Starting Member

7 Posts

Posted - 2002-01-16 : 05:41:57
Thanx for the link, but I allready had that one...

But we've got it working now, like this:

I found the following procedure:


create procedure sp_hexadecimal
@IntVal int
AS
DECLARE @Hex varchar(12)
SELECT @Hex = (SELECT
SUBSTRING( HexStr , ( @IntVal / POWER( 16 , 7 ) ) % 16 + 1 , 1 ) +
SUBSTRING( HexStr , ( @IntVal / POWER( 16 , 6 ) ) % 16 + 1 , 1 ) +
SUBSTRING( HexStr , ( @IntVal / POWER( 16 , 5 ) ) % 16 + 1 , 1 ) +
SUBSTRING( HexStr , ( @IntVal / POWER( 16 , 4 ) ) % 16 + 1 , 1 ) +
SUBSTRING( HexStr , ( @IntVal / POWER( 16 , 3 ) ) % 16 + 1 , 1 ) +
SUBSTRING( HexStr , ( @IntVal / POWER( 16 , 2 ) ) % 16 + 1 , 1 ) +
SUBSTRING( HexStr , ( @IntVal / POWER( 16 , 1 ) ) % 16 + 1 , 1 ) +
SUBSTRING( HexStr , ( @IntVal / POWER( 16 , 0 ) ) % 16 + 1 , 1 ) AS HexVal FROM (
SELECT '0123456789ABCDEF' AS HexStr
) AS a)

print @Hex

all you have to do is give an int as the parameter, and you get a string containing the hex value. And I find this a very clever solution (just a pity I forget where I found it... )

But this got us a long way, so everybody's happy...

C ya...

BAz

Go to Top of Page
   

- Advertisement -