BIT
Bit-field data type. A BIT(M) column stores M bits per value, allowing storage of binary values from 1 to 64 bits in length.
Syntax
BIT[(M)]Description
A bit-field type. M indicates the number of bits per value, from 1 to64. The default is 1 if M is omitted.
Bit values can be inserted with b'value' notation, where value is the bit value in 0's and 1's.
Bit fields are automatically zero-padded from the left to the full length of the bit, so for example in a BIT(4) field, '10' is equivalent to '0010'.
Bits are returned as binary, so to display them, either add 0, or use a function such as HEX, OCT or BIN to convert them.
Examples
Example of BIT:
CREATE TABLE bit_example (
description VARCHAR(20),
b1 BIT,
b4 BIT(4),
b16 BIT(16)
);With strict_mode set
This page is licensed: GPLv2, originally from fill_help_tables.sql
Last updated
Was this helpful?

