Convert hex to binary in MySQL

前端 未结 2 1312
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-01 17:51

Currently I search a function in MySQL to do conversion between hex string to binary representation, example:

0000 -> 0000000000000000
00AA -> 00000000         


        
2条回答
  •  佛祖请我去吃肉
    2021-01-01 18:24

    UNHEX('hex string')
    

    Would interpret each pair of characters in a string passed into the function as two hex characters and try to convert that to a binary number (binary format in mysql). This way, you can convert a string to binary. However, this won't display the content as a string of binary digits. Rather, each 2 bytes in the resulting string converted to the specific character encoding (for example utf8).

提交回复
热议问题