Given a binary(16) column, how do I display its value as a hexadecimal number? I\'ve been experimenting in the console a little below, and I\'m not getting the results I exp
Why make things complicated? I just use this to display the value of a BINARY(16)
column:
SELECT HEX(colname);
Use CONV function
-- convert '10000'(16 in binary) in hex
SELECT CONV('10000',2,16);
-- Ouput: 10
-- convert 'F' in hex to binary
SELECT CONV('F',16,2);
-- Output: 1111
Hexadecimal to binary table
Hexadecimal Binary
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
A 1010
B 1011
C 1100
D 1101
E 1110
F 1111
10 10000
11 10001
...
Just try this and you will clear your mind:
select conv(cast(10 as binary), 10, 16);
BINARY data type is treated as decimal string by default