Home > Database > Mysql Tutorial > How to convert value to binary in mysql

How to convert value to binary in mysql

青灯夜游
Release: 2022-06-16 17:28:46
Original
3719 people have browsed it

3 conversion methods: 1. Use the BIN() function to return the string representation of the binary value of the specified number. The syntax is "BIN(number)". The parameter "number" is a long integer ( BIGINT) number. 2. Use the CONV() function to convert one base to another. The syntax "CONV(number,10,2)" can return the binary value of the specified number. 3. Use the BINARY function to convert the value into a binary string, with the syntax "BINARY "value"".

How to convert value to binary in mysql

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

MySQL has three methods to convert values ​​to binary

Method 1: Use the BIN() function

The BIN() function returns the binary representation of a number as a string value; that is, the string representation of the binary value of a number.

BIN(number)
Copy after login
ParameterDescription
numberRequired item. A long integer (BIGINT) number

Example:

Returns the binary representation of 15

SELECT BIN(15);
Copy after login

How to convert value to binary in mysql

Return the binary representation of 8

How to convert value to binary in mysql

Method 2: Use the CONV() function

The CONV() function can Convert between digits, that is, convert between arbitrary bases.

CONV(number,10,2) is equivalent to BIN(number).

Example:

Return the binary representation of 15

How to convert value to binary in mysql

##Method 3: Use the BINARY function

BINARY function converts a value to a binary type string.

SELECT BINARY "值";
Copy after login

Example:


SELECT BINARY "15";
Copy after login

How to convert value to binary in mysql

[Related recommendations:

mysql video tutorial]

The above is the detailed content of How to convert value to binary in mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template