Description
A Bit in MySQL is also known as Bit-field values, which can be represented as b ‘value’ or 0b ‘value’. The term value is a binary value written in zeros and ones.
Examples
The following examples show the basic use of this literal:
mysql> CREATE TABLE t (b BIT(8));
mysql> INSERT INTO t SET b = b'11111111';
mysql> INSERT INTO t SET b = b'1010';
mysql> INSERT INTO t SET b = b'0101';
Binary values are returned in BIT values. Add 0 or BIN() to display the values in printable form.
mysql> SELECT b+0, BIN(b+0), OCT(b+0), HEX(b+0) FROM r;
Bit values which are assigned to the user variables are known as the Binary strings. Use CAST() or 0: to assign a bit value in user variable.
mysql> SET @c1 = 0b1000001;
mysql> SET @c2 = CAST(0b1000001 AS UNSIGNED),
@c3 = 0b1000001+0;
mysql> SELECT @c1, @c2, @c3;