BIN()
This page is part of MariaDB's Documentation.
The parent of this page is: Functions for MariaDB Xpand
Topics on this page:
Overview
Returns a string representation of the binary value of the given BIGINT
number.
USAGE
BIN(integer)
Argument Name | Description |
---|---|
| The number to convert to binary |
DETAILS
BIN()
is a string function that returns a string representation of a numerical argument transformed into binary.
A binary value is a number represented in the base-2 numeral system that makes use of only two symbols: 0
and 1
.
The returned value is always an integer, with floating point values being transformed into an integer using a floor function.
The returned values can be up to 64 bits (the size of a BIGINT
).
Negative input values are returned as two's complement positive values (where the highest bit being set indicates that the number is negative).
A NULL
is returned if the argument is NULL
.
EXAMPLES
SELECT BIN(5), BIN(42);
+--------+---------+
| BIN(5) | BIN(42) |
+--------+---------+
| 101 | 101010 |
+--------+---------+
SELECT BIN(-1);
+------------------------------------------------------------------+
| BIN(-1) |
+------------------------------------------------------------------+
| 1111111111111111111111111111111111111111111111111111111111111111 |
+------------------------------------------------------------------+