Example 1 — Basic decbin() usage
This example turns a few decimal numbers into binary strings.
<?php
echo decbin(10) . PHP_EOL;
echo decbin(255) . PHP_EOL;
echo decbin(5) . PHP_EOL;
echo decbin(0) . PHP_EOL; How It Works
- 10 is 8 + 2, so the binary form is 1010.
- 255 needs eight 1 digits: 11111111.
- 5 is 4 + 1, which is 101.
- 0 is simply 0.

