mysql HEX将字符串或数字转化为16进制字符串、UNHEX将16字符串转化成二进制
目錄
- 前言
- HEX
- HEX 函數的參數為數字時
- HEX 函數的參數為字符串時
- UNHEX
- HEX 將 binary 類型轉化為字符串
前言
- mysql 5.7.31
HEX
HEX 函數的官方說明如下:
HEX(str), HEX(N)
For a string argument str, HEX() returns a hexadecimal string representation of str where each byte of each character in str is converted to two hexadecimal digits. (Multibyte characters therefore become more than two digits.) The inverse of this operation is performed by the UNHEX() function.
For a numeric argument N, HEX() returns a hexadecimal string representation of the value of N treated as a longlong (BIGINT) number. This is equivalent to CONV(N,10,16). The inverse of this operation is performed by CONV(HEX(N),16,10).
- 參數:可接受數字和字符串類型的參數
- 返回值:十六進制值的字符串
HEX 函數的參數為數字時
函數作用:數字參數N(十進制) -> 十六進制的數值=CONV(N,10,16) -> 將十六進制的數值轉化為字符串
mysql> select HEX(48); +---------+ | HEX(48) | +---------+ | 30 | +---------+ 1 row in set (0.01 sec)- 在ASCII碼表中,字符'0'對應的十六進制數字為0x30。十六進制數字0x30對應的十進制數字為48。
- 在ASCII碼表中,字符'0'對應的十六進制數字為0x30。十六進制數字0x30對應的十進制數字為48。
HEX 函數的參數為字符串時
函數作用:字符串參數S -> 字符串中的每個字符(按照ASCII碼表)轉化成ASCII碼(十六進制數值) -> 將十六進制的數值轉化為字符串
mysql> select HEX('0'); +----------+ | HEX('0') | +----------+ | 30 | +----------+ 1 row in set (0.01 sec)- 在ASCII碼表中,字符'0'對應的十六進制數字為0x30。十六進制數字0x30對應的十進制數字為48。
UNHEX
UNHEX函數的官方說明如下:
UNHEX(str)
For a string argument str, UNHEX(str) interprets each pair of characters in the argument as a hexadecimal number and converts it to the byte represented by the number. The return value is a binary string.
- 參數:字符串類型的參數
- 返回值:二進制值的字符串
- 函數作用:字符串參數S -> 字符串中每2位字符(按照ASCII碼表)轉化為一個十六進制數值 -> 將十六進制的數值轉化為字符
- 在ASCII碼表中,字符'0'對應的十六進制數字為0x30。十六進制數字0x30對應的十進制數字為48。
HEX 將 binary 類型轉化為字符串
總結
以上是生活随笔為你收集整理的mysql HEX将字符串或数字转化为16进制字符串、UNHEX将16字符串转化成二进制的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 搜狗手机输入法怎样更改键盘壁纸教程
- 下一篇: 【MySQL】错误#1217:外键约束引