Convert INT to HEX

How can I convert 15 -> F

I can do convert(varbinary(1),15) and get 0x0F but I can get that 'F' into a variable. Casting to a string isn't working.
elmoredanielAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:

select  right(master.dbo.fn_varbintohexstr(convert(varbinary(1),15)),1)
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
does this not work:
cast(convert(varbinary(1),15) as varchar(10))
0
 
elmoredanielAuthor Commented:
No, it returns an unreadable character.
0
 
auke_tCommented:
CREATE function DECTOHEX(@n int )
--Converts a decimal number to hexadecimal.
returns varchar(255)
as
BEGIN
DECLARE @i int,@temp int, @s varchar(255)
SET @i=@n
SET @s=''
WHILE (@i>0)
BEGIN
SET @temp=@i % 16
SET @i=@i /16
IF @temp>9
      SET @s=char(55+@temp)+@s
ELSE
      SET @s=char(48+@temp)+@s
END
RETURN @s
END


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.