Skip to content

Endian

PHP Version RequirementGitHub ReleaseCode Coverage

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
  1. In big endian byte order.
php
use Thesis\Endian;

echo Endian\Order::big->unpackInt8(
    Endian\Order::big->packInt8(17),
); // 17
  1. In little endian byte order.
php
use Thesis\Endian;

echo Endian\Order::little->unpackFloat(
    Endian\Order::little->packFloat(2.2),
); // 2.2
  1. 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