How to use bitmasks in PHP
Or other languages. It’s the same concept.
Published in
4 min readMar 28, 2022
Bitmasks are as old as computing itself and, admittedly, were more useful in the days of memory scarcity and low-level programming. But there’s nothing to stop you using them today, when appropriate.
PHP makes use of bitmasks in many of its built-in functions. Consider:
json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
(my personal favourite way of calling json_encode…)