Mysql Bin Function

MySQL: BIN Function

This tutorial explains how to use the MySQL BIN function with syntax and examples.

Description

The MySQL BIN function converts a decimal number to a binary number and returns the result as a string value.

Syntax

The syntax for the BIN function in MySQL is:

BIN( number )

Parameters or Arguments

number

The number to convert to a binary representation.

Note

  • The BIN function returns the binary representation as a string value.
  • The BIN function is equivalent to using the CONV function with CONV(number,10,2) syntax.

Applies To

The BIN function can be used in the following versions of MySQL:

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

Example

Let's look at some MySQL BIN function examples and explore how to use the BIN function in MySQL.

For example:

mysql> SELECT BIN(5);
Output: '101'

mysql> SELECT BIN(6);
Output: '110'

mysql> SELECT BIN(99);
Output: '1100011'