?
Solved

Convert INT to HEX

Posted on 2006-05-21
4
Medium Priority
?
1,173 Views
Last Modified: 2012-06-21
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.
0
Comment
Question by:elmoredaniel
  • 2
4 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16731805
does this not work:
cast(convert(varbinary(1),15) as varchar(10))
0
 

Author Comment

by:elmoredaniel
ID: 16731810
No, it returns an unreadable character.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 16731858

select  right(master.dbo.fn_varbintohexstr(convert(varbinary(1),15)),1)
0
 
LVL 9

Expert Comment

by:auke_t
ID: 16731890
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

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question