https://github.com/thesis-php/endian
Library for encoding and decoding numbers in either big-endian or little-endian order.
https://github.com/thesis-php/endian
Last synced: 3 months ago
JSON representation
Library for encoding and decoding numbers in either big-endian or little-endian order.
- Host: GitHub
- URL: https://github.com/thesis-php/endian
- Owner: thesis-php
- License: mit
- Created: 2025-01-15T03:02:51.000Z (over 1 year ago)
- Default Branch: 0.3.x
- Last Pushed: 2026-03-05T09:14:25.000Z (3 months ago)
- Last Synced: 2026-03-05T12:59:41.115Z (3 months ago)
- Language: PHP
- Size: 96.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Endian
[](https://packagist.org/packages/thesis/endian)
[](https://github.com/thesisphp/endian/releases)
[](https://codecov.io/gh/thesis-php/endian/tree/0.1.x)
## Installation
```shell
composer require thesis/endian
```
## Read/write in any byte order:
1. In `network` (`big endian`) byte order.
```php
use Thesis\Endian;
echo Endian\Order::network->unpackInt32(
Endian\Order::network->packInt32(-200),
); // -200
```
2. In `big endian` byte order.
```php
use Thesis\Endian;
echo Endian\Order::big->unpackInt8(
Endian\Order::big->packInt8(17),
); // 17
```
3. In `little endian` byte order.
```php
use Thesis\Endian;
echo Endian\Order::little->unpackFloat(
Endian\Order::little->packFloat(2.2),
); // 2.2
```
4. In `native endian` byte order.
```php
use Thesis\Endian;
use BcMath\Number;
echo Endian\Order::native()
->unpackInt64(
Endian\Order::native()->packInt64(new Number('9223372036854775807')),
)
->value; // 9223372036854775807
```
### Supported types:
- [x] `int8`
- [x] `uint8`
- [x] `int16`
- [x] `uint16`
- [x] `int32`
- [x] `uint32`
- [x] `int64`
- [x] `uint64`
- [x] `float`
- [x] `double`