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.
| 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?ThanxBAz |
|
|
chadmat
The Chadinator
1974 Posts |
|
|
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 intASDECLARE @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 @Hexall 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 |
 |
|
|
|
|
|
|
|