Answer the question
In order to leave comments, you need to log in
bitmask in php
there is a desire to store boolean values as a bitmask.
for example, yes-no-yes will be 1-0-1
as I understand it, you can store something like this 2^1 + 2^0 + 2^3 = 2+1+8=11
I can’t find an example. and is it worth bothering and is it easier to store as 101 and stupidly pull out the element by number in the tuple? the variant with powers of two seems to allow an unlimited increase in the length of the tuple. the truth and complexity of decoding is higher.
----
$store = 0;
$n = 2;
$store = $store | (1<<$n);
$n = 4;
$store = $store | (1<<$n);
var_dump($store);
Answer the question
In order to leave comments, you need to log in
What do you want an example of? Writing the nth bit into a number: store = store | (1<<n)
, given that the bits are counted from zero.
habrahabr.ru/post/134557
here is an article that answers all your questions
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question