https://github.com/navarr/binary-explode
Explode a number into it's binary components
https://github.com/navarr/binary-explode
Last synced: 7 months ago
JSON representation
Explode a number into it's binary components
- Host: GitHub
- URL: https://github.com/navarr/binary-explode
- Owner: navarr
- License: mit
- Created: 2017-01-06T19:44:41.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2022-04-03T14:22:31.000Z (over 4 years ago)
- Last Synced: 2024-12-29T06:22:24.238Z (over 1 year ago)
- Language: PHP
- Size: 26.4 KB
- Stars: 0
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Binary Exploders
[](https://packagist.org/packages/navarr/binary-explode)
[](https://packagist.org/packages/navarr/binary-explode)
[](https://packagist.org/packages/navarr/binary-explode)
[](https://packagist.org/packages/navarr/binary-explode)


[](https://dashboard.stryker-mutator.io/reports/github.com/navarr/binary-explode/main)
This package provides two functions usable to convert a number into an array of it's binary components.
Examples:
1. \[1]
2. \[2]
3. \[2, 1]
4. \[4]
5. \[4, 1]
6. \[4, 2]
7. \[4, 2, 1]
etc
## Usage
### Installation
```
composer require navarr/binary-explode`
```
### Shared Interface
This package provides a shared interface, `\Navarr\BinaryExploder\BinaryExploderInterface`. This interface takes an `int` and returns an `iterable` containing or generating the binary components of that `int`.
### \Navarr\BinaryExploder\LinearBinaryExploder::explode(int $value) : iterable
Uses a linear algorithm that checks the logical AND of the number with increasing powers of 2.
This algorithm is typically fastest for numbers that are unlikely to be a power of 2.
### Navarr\BinaryExploder\LogarithmicBinaryExploder::explode(int $value) : iterable
Uses a linear algorithm that checks the log(base 2) of the number and then it's remainders.
This algorithm is typically fastest for numbers that are likely to be a power of 2.