lundi 12 novembre 2018

Is there a way to use a bunch of bits (or one byte) instead of a bunch of booleans?

I am currently thinking of a way to store checkbox values (true/false) in a database, without using a boolean column for each checkbox. Is there a way to store them in a byte that contains the information for, let's say, six checkboxes?

For example:
* Checkbox 1 to 6 all unchecked would be 00000000
* Checkbox 1 to 6 all checked would be 00111111
* Checkbox 1 checked, rest unchecked would be 00000001
* Checkbox 3 and 4 checked, rest unchecked would be 00001100
* etc.

In the end there would be one byte column and for each row a different combination for checkboxes checked/unchecked.

Would this make sense as an alternative to a bunch of boolean columns (one for each checkbox)?

Is there a better way to handle checkbox values in the db?

Is there a way to set each bit of a byte manually in C#? I can't seem to find an explanation on how to do this.




Aucun commentaire:

Enregistrer un commentaire