PHPackages                             thesis/endian - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. thesis/endian

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

thesis/endian
=============

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

0.3.3(3mo ago)149.5k↓58.1%[1 PRs](https://github.com/thesis-php/endian/pulls)8MITPHPPHP ^8.4CI passing

Since Jan 15Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/thesis-php/endian)[ Packagist](https://packagist.org/packages/thesis/endian)[ Fund](https://www.tinkoff.ru/cf/5MqZQas2dk7)[ RSS](/packages/thesis-endian/feed)WikiDiscussions 0.3.x Synced 3w ago

READMEChangelog (6)Dependencies (8)Versions (12)Used By (8)

Endian
======

[](#endian)

[![PHP Version Requirement](https://camo.githubusercontent.com/045b9cb42a4920f7520a690f4502b1e04265153a4ad56ac9365a57621c3b5df6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f7468657369732f656e6469616e2f706870)](https://packagist.org/packages/thesis/endian)[![GitHub Release](https://camo.githubusercontent.com/e56acec4324f5d46112dd4c955a58fdc7b3a0ec53bfbfc522698187a0a751151/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f7468657369737068702f656e6469616e)](https://github.com/thesisphp/endian/releases)[![Code Coverage](https://camo.githubusercontent.com/dfa6b887810b0e9769d4e2b292e5efaee1ef5d24844b0fa92824516a989d944c/68747470733a2f2f636f6465636f762e696f2f67682f7468657369732d7068702f656e6469616e2f6272616e63682f302e342e782f67726170682f62616467652e737667)](https://codecov.io/gh/thesis-php/endian/tree/0.4.x)

Pack and unpack binary integers and floats in any byte order.

Installation
------------

[](#installation)

```
composer require thesis/endian
```

Usage
-----

[](#usage)

```
use Thesis\Endian;

// Big endian (= network byte order)
$bytes = Endian\Order::Big->packInt32(-200);
$value = Endian\Order::Big->unpackInt32($bytes); // -200
$bytes = Endian\Order::Network->packInt32(-200);
$value = Endian\Order::Network->unpackInt32($bytes); // -200

// Little endian
$bytes = Endian\Order::Little->packFloat(2.2);
$value = Endian\Order::Little->unpackFloat($bytes); // 2.2

// Native byte order of the current machine
$order = Endian\Order::native(); // Order::Big or Order::Little
```

Design decisions
----------------

[](#design-decisions)

### No narrow int types on input

[](#no-narrow-int-types-on-input)

Pack methods accept plain `int` rather than narrow PHPStan types like `Int8` or `Int32`. This is intentional: requiring callers to carry and assert narrow types would flood driver code with redundant checks and type imports. Thus, we've decided to keep the validation on our side.

Bounds are checked with [`assert()`](https://www.php.net/manual/en/function.assert.php), which means zero overhead in production when assertions are disabled ([`zend.assertions = -1`](https://www.php.net/manual/en/info.configuration.php#ini.zend.assertions)).

### No object wrappers for 8/16/32-bit

[](#no-object-wrappers-for-81632-bit)

8/16/32-bit integers are represented as native PHP `int`, not value objects. This avoids allocation and method-call overhead on every pack/unpack — important in tight loops typical of binary protocol parsing.

### 64-bit integers

[](#64-bit-integers)

64-bit values use [`BcMath\Number`](https://www.php.net/manual/en/class.bcmath-number.php)to handle the full unsigned range beyond `PHP_INT_MAX`:

```
use Thesis\Endian;
use BcMath\Number;

$bytes = Endian\Order::Big->packUint64(new Number('18446744073709551615'));
$value = Endian\Order::Big->unpackUint64($bytes); // 18446744073709551615
```

Supported types
---------------

[](#supported-types)

TypePHP typeRange`int8``int``−128 .. 127``uint8``int``0 .. 255``int16``int``−32 768 .. 32767``uint16``int``0 .. 65535``int32``int``−2147483648 .. 2147483647``uint32``int``0 .. 4294967295``int64``BcMath\Number``−2⁶³ .. 2⁶³−1``uint64``BcMath\Number``0 .. 2⁶⁴−1``float``float`[32-bit IEEE 754](https://en.wikipedia.org/wiki/Single-precision_floating-point_format)`double``float`[64-bit IEEE 754](https://en.wikipedia.org/wiki/Double-precision_floating-point_format)

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance81

Actively maintained with recent releases

Popularity32

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 65.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~56 days

Recently: every ~33 days

Total

9

Last Release

107d ago

PHP version history (2 changes)0.1.0PHP ^8.3

0.3.0PHP ^8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2552865?v=4)[Valentin Udaltsov](/maintainers/vudaltsov)[@vudaltsov](https://github.com/vudaltsov)

---

Top Contributors

[![kafkiansky](https://avatars.githubusercontent.com/u/37590388?v=4)](https://github.com/kafkiansky "kafkiansky (15 commits)")[![vudaltsov](https://avatars.githubusercontent.com/u/2552865?v=4)](https://github.com/vudaltsov "vudaltsov (8 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/thesis-endian/health.svg)

```
[![Health](https://phpackages.com/badges/thesis-endian/health.svg)](https://phpackages.com/packages/thesis-endian)
```

###  Alternatives

[tkaratug/tcmb_currency_converter

TCMB Currenct Converter

201.0k](/packages/tkaratug-tcmb-currency-converter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
