©SQL :: Manager
HomeProgram InformationTechnical detailsFree downloadDonate for a cup of coffee
myway SQL Manager for MySQL and MariaDB, Download on Uptodown
SQL functionMySQLMariaDB

The BIN SQL Function in MySQL and MariaDB - Binary string

BINSyntax:BIN(Integer)
Return value:CHAR
Function type:Conversion function
Function Description

The BIN() function returns a string with the binary representation of an "Integer".

BIN() corresponds to the function CONV(Number,10,2), floating point values are rounded down to integer.

Character strings are interpreted as integers.

If the argument is not a number, the function returns 0.

If the value of the argument is NULL, BIN() returns NULL.

SQL Examples for the BIN function

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15

SELECT bin(128);
SELECT bin(15);
SELECT bin(-128);
SELECT conv(128,10,2);
SELECT conv(15,10,2);

SELECT bin(1.2);
SELECT bin(1.6);

SELECT bin('Test');
SELECT bin('128');

SELECT hex(null);

bin(128)
varchar(64) BINARY
10000000
bin(15)
varchar(64) BINARY
1111
bin(-128)
varchar(64) BINARY
1111111111111111111111111111111111111111111111111111111110000000
conv(128,10,2)
varchar(64) BINARY
10000000
conv(15,10,2)
varchar(64) BINARY
1111
bin(1.2)
varchar(64) BINARY
1
bin(1.6)
varchar(64) BINARY
1
bin('Test')
varchar(64) BINARY
0
bin('128')
varchar(64) BINARY
10000000
hex(null)
varchar(0) BINARY
NULL
The examples were created with the MyWAY SQL manager: Download

How to use the BIN() function in MySQL and MariaDB databases

The BIN() function in MySQL and MariaDB is used to convert a decimal or integer value into its binary representation. The function takes a numeric value as input and returns a string representing the binary form with "0" and "1" characters of that value, for example for use in binary arithmetic or handling binary data.

The result of the function is a string and not a binary value. To perform binary operations or to store binary data, the corresponding binary data types such as BINARY, VARBINARY or BLOB should be used.
ATAN2AVGBENCHMARKBINBIN_TO_UUIDBIT_ANDBIT_COUNT

Further MySQL und MariaDB SQL Conversion functions

CASTCAST(Value AS Type)
More about CAST Function

CONVCONV(Value, from Base, to Base)
More about CONV Function

CONVERTCONVERT(Expression [, in type] [, or character set])
More about CONVERT Function

HEXHEX(Integer or 'string')
More about HEX Function

OCTOCT(Integer)
More about OCT Function

UNHEXUNHEX(String)
More about UNHEX Function

Numeric functionsString functionsRegular ExpressionsDate and Time functions
Comparison functionsEncryption & CompressionConversion functionsNULL functions
Aggregate functionsWindow functionsJSON functionsGeometric functions
Sequence functionsInformation functionsDynamic ColumnsMiscellaneous functions
More information about the BIN SQL function: mysql.com and mariadb.com
Updated: 2023-09-24ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer