mysql HEX将字符串或数字转化为16进制字符串、UNHEX将16字符串转化成二进制
目錄
- 前言
- HEX
- HEX 函數(shù)的參數(shù)為數(shù)字時(shí)
- HEX 函數(shù)的參數(shù)為字符串時(shí)
- UNHEX
- HEX 將 binary 類型轉(zhuǎn)化為字符串
前言
- mysql 5.7.31
HEX
HEX 函數(shù)的官方說(shuō)明如下:
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).
- 參數(shù):可接受數(shù)字和字符串類型的參數(shù)
- 返回值:十六進(jìn)制值的字符串
HEX 函數(shù)的參數(shù)為數(shù)字時(shí)
函數(shù)作用:數(shù)字參數(shù)N(十進(jìn)制) -> 十六進(jìn)制的數(shù)值=CONV(N,10,16) -> 將十六進(jìn)制的數(shù)值轉(zhuǎn)化為字符串
mysql> select HEX(48); +---------+ | HEX(48) | +---------+ | 30 | +---------+ 1 row in set (0.01 sec)- 在ASCII碼表中,字符'0'對(duì)應(yīng)的十六進(jìn)制數(shù)字為0x30。十六進(jìn)制數(shù)字0x30對(duì)應(yīng)的十進(jìn)制數(shù)字為48。
- 在ASCII碼表中,字符'0'對(duì)應(yīng)的十六進(jìn)制數(shù)字為0x30。十六進(jìn)制數(shù)字0x30對(duì)應(yīng)的十進(jìn)制數(shù)字為48。
HEX 函數(shù)的參數(shù)為字符串時(shí)
函數(shù)作用:字符串參數(shù)S -> 字符串中的每個(gè)字符(按照ASCII碼表)轉(zhuǎn)化成ASCII碼(十六進(jìn)制數(shù)值) -> 將十六進(jìn)制的數(shù)值轉(zhuǎn)化為字符串
mysql> select HEX('0'); +----------+ | HEX('0') | +----------+ | 30 | +----------+ 1 row in set (0.01 sec)- 在ASCII碼表中,字符'0'對(duì)應(yīng)的十六進(jìn)制數(shù)字為0x30。十六進(jìn)制數(shù)字0x30對(duì)應(yīng)的十進(jìn)制數(shù)字為48。
UNHEX
UNHEX函數(shù)的官方說(shuō)明如下:
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.
- 參數(shù):字符串類型的參數(shù)
- 返回值:二進(jìn)制值的字符串
- 函數(shù)作用:字符串參數(shù)S -> 字符串中每2位字符(按照ASCII碼表)轉(zhuǎn)化為一個(gè)十六進(jìn)制數(shù)值 -> 將十六進(jìn)制的數(shù)值轉(zhuǎn)化為字符
- 在ASCII碼表中,字符'0'對(duì)應(yīng)的十六進(jìn)制數(shù)字為0x30。十六進(jìn)制數(shù)字0x30對(duì)應(yīng)的十進(jìn)制數(shù)字為48。
HEX 將 binary 類型轉(zhuǎn)化為字符串
總結(jié)
以上是生活随笔為你收集整理的mysql HEX将字符串或数字转化为16进制字符串、UNHEX将16字符串转化成二进制的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 搜狗手机输入法怎样更改键盘壁纸教程
- 下一篇: 【若依(ruoyi)】启动时,卡死在:U