MySQL storage of binary numbers


There are numbers like: 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 (168 characters).

These numbers are a set of 168-point configurations, in the form of TRUE(1) and FALSE(0) .

What is the best way to store it so that it does not take up space and quickly read it and write it to the database?

In what type of fields is it better to store them?

I will correct the problem: a set of 168 digits is the hourly settings for every day. That is, 7×24 = 168. It is required to write this config bit by bit in the PHP + MySQL link into the list -> (field) settings table.


mysqli_query($con,"INSERT INTO list (settings) 
VALUES ($settings)");


Now the database structure is as follows:

`settings` tinyblob NOT NULL,

Takes up this case, respectively [BLOB – 168 Bytes]
I would like to fit into 168 bits (+ -), since there will be many such configs.
How do I implement this in PHP?


If this is really a set of settings, then it is better to store it in a separate table, in the format "name – on / off flag".

The full set of settings is read out in the same way with one request, and it will be much easier to work with it at times. Especially if at some point you have to delete setting # 40.

For an updated version of the question – if these are hourly settings – they should be stored in a table like

Номер конфига | День недели | Час | On/Off

And you don't have to work with bits at all. You can safely download the entire config, and in one call find out the setting for the right hour of the right day.

If you are worried about the occupied volume – in vain. This is about a kilobyte per config. Approximately $ 0.00000004 at current storage prices.

Scroll to Top