lundi 18 février 2019

customize functions in Laravel

I am curious about ($value & ($value - 1)) != 0 that how it is working in below validation to know number is power of 2?!

function ($attribute, $value, $fail) {
                    if ($value == 0 || ($value & ($value - 1)) != 0) {
                        $fail($attribute . ' is not power of 2!');
                    }
                }

If I would like get numbers between numbers of power 2 beyond power 2 numbers, what shall I do? can I use and modify this command? (e.g. numbers: 1,2,3,4,6,8,12,16,...)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire