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
 General SQL Server Forums
 New to SQL Server Programming
 Negative Decimal Integer to varchar Hexadecimal

Author  Topic 

challapavan
Starting Member

8 Posts

Posted - 2008-09-26 : 10:27:35
How to convert a negative Decimal Integer to varchar Hexadecimal.

Please find the attached sample.

If we convert -1048284 to Binary we will get

1111111111111111111111111111111111111111111100000000000100100100.

And converting this to Hex value will give us: FFFFFFFFFFF00124


Thanks in advance.....

pavan

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-09-26 : 10:31:16
[code]DECLARE @Sample INT

SET @Sample = -1048284

SELECT CAST(@Sample AS BINARY(4))[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-09-26 : 10:36:15
[code]DECLARE @bigSample BIGINT,
@intSample INT

SELECT @bigSample = -1048284,
@intSample = -1048284

SELECT CAST(@bigSample AS BINARY(8)) AS [64-bit],
CAST(@intSample AS BINARY(4)) AS [32-bit][/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -