Display binary(16) column as hex in mysql

前端 未结 3 1295
傲寒
傲寒 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: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
    ...
    

提交回复
热议问题