Display binary(16) column as hex in mysql

前端 未结 3 1294
傲寒
傲寒 2021-01-20 00:23

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

相关标签:
3条回答
  • 2021-01-20 01:02

    Why make things complicated? I just use this to display the value of a BINARY(16) column:

    SELECT HEX(colname);

    0 讨论(0)
  • 2021-01-20 01:06

    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
    ...
    
    0 讨论(0)
  • 2021-01-20 01:22

    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

    0 讨论(0)
提交回复
热议问题