Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL int to hex conversion little/big endian format

Tags:

sql-server

Using MSSMS I'm trying to run the query.

SELECT CONVERT(BINARY(16), 14437)

It results to:

0x00000000000000000000000000003865

But this is what I'm looking for:

0x65380000000000000000000000000000

I tried using reverse but no luck.

SELECT REVERSE(CONVERT(BINARY(16), 14437))
like image 544
madziikoy Avatar asked Mar 24 '13 10:03

madziikoy


1 Answers

I tried using reverse but no luck.

REVERSE returns a string. Casting back to binary returns your desired results

SELECT CONVERT(BINARY(16), REVERSE(CONVERT(BINARY(16), 14437)))
like image 98
Martin Smith Avatar answered Sep 17 '22 14:09

Martin Smith