<commit_before>The naive way of storing this (in a database) is to create for each option a field and storing a `0` when it is `false` and `1` when it was `true`. Consider the following example, something some of you might have written in some variant.

```php
<?php
class Config
{
    public $option1 = false;
    public $option2 = false;
    public $option3 = false;
    public $option4 = false;
    public $option5 = false;
    // ...
}
```

Which of course works, bit adding options will require a new field, which might require creating a compatibility layer for your old data. Moreover, checking multiple options at once requires to expressions. There is an easier way to do this and it's even more efficient at checking fields.

This brings me to an old topic which I have to explain to all the new people at some point and even once explained not everybody understand how it actually works. So in this post I'm going to explain how to use bitwise operators and how it works.

## Setup
Looking back at our example, a couple of changes need to be made. Instead of booleans and fields, the `Config` class will contain constants. Each constant will be a value fits our formula `2^x` as long as `x` is positive. So our first constant will be `2^0` which is `1`. The second `2^1` is `2`. The third `2^2` is `4` and so on.

The result is:
```php
<?php
class Config
{
    const OPTION_1 = 1;
    const OPTION_2 = 2;
    const OPTION_3 = 4;
    const OPTION_4 = 8;
    const OPTION_5 = 16;<commit_msg>Update bitwise-flags.md<commit_after>The naive way of storing many boolean options (in a database) is to create for each option a field and storing a `0` when it is `false` and `1` when it is `true`. Consider the following example, something some of you might have written in some variant.

```php
<?php
class Config
{
    public $option1 = false;
    public $option2 = false;
    public $option3 = false;
    public $option4 = false;
    public $option5 = false;
    // ...
}
```

Which of course works, bit adding options will require a new field, which might require creating a compatibility layer for your old data. There is an easier way to do this and it's even more efficient at checking fields.

This brings me to an old topic which I have to explain to all the new people at some point and even once explained not everybody understands how it actually works. So in this post I'm going to explain how to use bitwise operators and how it works internally.

## Setup
Looking back at our example, a couple of changes need to be made. Instead of booleans and fields, the `Config` class will contain constants. Each constant will be a value fits our formula `2^x` as long as `x` is positive. So our first constant will be `2^0` which is `1`. The second `2^1` is `2`. The third `2^2` is `4` and so on.

The result is:
```php
<?php
class Config
{
    const OPTION_1 = 1;
    const OPTION_2 = 2;
    const OPTION_3 = 4;
    const OPTION_4 = 8;
    const OPTION_5 = 16;
{'fraction_non_alphanumeric': 0.07075471698113207, 'fraction_numerical': 0.018867924528301886, 'mean_word_length': 3.532824427480916, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1841853', 'n_tokens_mistral': 850, 'n_tokens_neox': 817, 'n_words': 486}