madziikoy
madziikoy

Reputation: 1497

SQL int to hex conversion little/big endian format

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))

Upvotes: 7

Views: 4035

Answers (1)

Martin Smith
Martin Smith

Reputation: 453608

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)))

Upvotes: 10

Related Questions