Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HEX TO BINARY

Status
Not open for further replies.

RaulMA

Programmer
Apr 4, 2006
19
US
Could some one provide a function to convert HEX TO BINARY?
 
I use below to do this for inserting a record into a table. A kind gentlement from India actually helped me with it and it works. If it ever breaks I am in trouble

--insert into dental
Declare @error varchar(100)
DECLARE @IntVal int
declare @hexright varchar(5)
SELECT @IntVal = @vactid
declare @hexfinal varchar(12)
SELECT @hexfinal = 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 )
FROM (
SELECT '0123456789ABCDEF' AS hexstr
) AS h
select @hexright = right(@hexfinal,5)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top