Skip to content

Library for encoding and decoding numbers in either big-endian or little-endian order.

License

Notifications You must be signed in to change notification settings

thesis-php/endian

Repository files navigation

Endian

PHP Version Requirement GitHub Release Code Coverage

Installation

composer require thesis/endian

Read/write in any byte order:

  1. In network (big endian) byte order.
use Thesis\Endian;

echo Endian\Order::network->unpackInt32(
    Endian\Order::network->packInt32(-200),
); // -200
  1. In big endian byte order.
use Thesis\Endian;

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

echo Endian\Order::little->unpackFloat(
    Endian\Order::little->packFloat(2.2),
); // 2.2
  1. In native endian byte order.
use Thesis\Endian;
use BcMath\Number;

echo Endian\Order::native()
    ->unpackInt64(
        Endian\Order::native()->packInt64(new Number('9223372036854775807')),
    )
    ->value; // 9223372036854775807

Supported types:

  • int8
  • uint8
  • int16
  • uint16
  • int32
  • uint32
  • int64
  • uint64
  • float
  • double

About

Library for encoding and decoding numbers in either big-endian or little-endian order.

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published