thesis/endian

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

0.1.0 2025-01-15 04:45 UTC

This package is auto-updated.

Last update: 2025-01-16 07:11:17 UTC


README

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.
<?php

declare(strict_types=1);

require_once __DIR__.'/vendor/autoload.php';

use Thesis\Endian\endian;

echo endian::network->unpackInt32(
    endian::network->packInt32(-200),
); // -200
  1. 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
  1. 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
  1. 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