thesis / endian
Library for encoding and decoding numbers in either big-endian or little-endian order.
Fund package maintenance!
www.tinkoff.ru/cf/5MqZQas2dk7
0.1.0
2025-01-15 04:45 UTC
Requires
- php: ^8.3
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.8.2
- ergebnis/composer-normalize: ^2.45.0
- phpunit/phpunit: ^10.5.40
README
Installation
composer require thesis/endian
Read/write in any byte order:
- In
network
(big endian
) byte order.
<?php declare(strict_types=1); require_once __DIR__.'/vendor/autoload.php'; use Thesis\Endian\endian; echo endian::network->unpackInt32( endian::network->packInt32(-200), ); // -200
- In
big endian
byte order.
<?php declare(strict_types=1); require_once __DIR__.'/vendor/autoload.php'; use Thesis\Endian\endian; echo endian::big->unpackInt8( endian::big->packInt8(17), ); // 17
- In
little endian
byte order.
<?php declare(strict_types=1); require_once __DIR__.'/vendor/autoload.php'; use Thesis\Endian\endian; echo endian::little->unpackFloat( endian::little->packFloat(2.2), ); // 2.2
- In
native endian
byte order.
<?php declare(strict_types=1); require_once __DIR__.'/vendor/autoload.php'; use Thesis\Endian\endian; echo endian::native->unpackInt64( endian::native->packInt64(\PHP_INT_MAX), ); // 9223372036854775807
Supported types:
-
int8
-
uint8
-
int16
-
uint16
-
int32
-
uint32
-
int64
-
uint64
-
float
-
double