PHPackages                             hsldymq/byte-order-op - 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. hsldymq/byte-order-op

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

hsldymq/byte-order-op
=====================

字节序操作工具

v0.1.2(4y ago)07341MITPHPPHP ^7.0 || ^8.0CI failing

Since Jan 20Pushed 4y ago1 watchersCompare

[ Source](https://github.com/hsldymq/byte-order-op)[ Packagist](https://packagist.org/packages/hsldymq/byte-order-op)[ RSS](/packages/hsldymq-byte-order-op/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (1)

字节序操作工具
=======

[](#字节序操作工具)

[![tests](https://github.com/hsldymq/byte-order-op/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/hsldymq/byte-order-op/actions/workflows/unit-tests.yml/badge.svg)[![codecov](https://camo.githubusercontent.com/94d64f3b33ee18a3e03529d8c97de878826eff84f8b89e48d6acd4c64ac10862/68747470733a2f2f636f6465636f762e696f2f67682f68736c64796d712f627974652d6f726465722d6f702f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d574d4958314b424c4834)](https://codecov.io/gh/hsldymq/byte-order-op)

**用于将数据在小端和大端存储之间转换.**

例如当前机器为64位小端机器,对于整型数字127,在内存中存储结构为:

`01111111 00000000 00000000 00000000 00000000 00000000 00000000 00000000`

转换为大端后,数字变为9151314442816847872, 内存中存储为:

`00000000 00000000 00000000 00000000 00000000 00000000 00000000 01111111`

### PHP 版本

[](#php-版本)

PHP 7.0+ || PHP 8.0+

安装
--

[](#安装)

```
composer require hsldymq/byte-order-op
```

Examples
--------

[](#examples)

```
    use Archman\ByteOrder\ByteOrder;

    // 获得当前机器字节序
    // $bo的值只有两种: ByteOrder::LITTLE_ENDIAN和ByteOrder::BIG_ENDIAN
    $bo = ByteOrder::get();
```

```
    use Archman\ByteOrder\ByteOrder;

    // 等同于 ByteOrder::get() === ByteOrder::LITTLE_ENDIAN
    if (ByteOrder::isLittleEndian()) {
        // ...
    }

```

```
    use Archman\ByteOrder\ByteOrder;
    use Archman\ByteOrder\Operator;

    // 将该值(此处为127)转换为小端字节数组表示, 无论当前机器为小端还是大端
    // 于是其输出应该为(从左到右为低字节到高字节):
    // 64位机器: 0x7F 0x00 0x00 0x00 0x00 0x00 0x00 0x00
    // 32位机器: 0x7F 0x00 0x00 0x00
    $byteArrLE = Operator::toByteArray(127, ByteOrder::LITTLE_ENDIAN);
    if (PHP_INT_SIZE === 8) {
        assert($byteArrLE === "\x7F\x00\x00\x00\x00\x00\x00\x00");
    } else {
        assert($byteArrLE === "\x7F\x00\x00\x00");
    }

    // 输出应该为(从左到右为低字节到高字节):
    // 64位机器: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x7F
    // 32位机器: 0x00 0x00 0x00 0x7F
    $byteArrBE = Operator::toByteArray(127, ByteOrder::BIG_ENDIAN);
    if (PHP_INT_SIZE === 8) {
        assert($byteArrLE === "\x00\x00\x00\x00\x00\x00\x00\x7F");
    } else {
        assert($byteArrLE === "\x00\x00\x00\x7F");
    }
```

```
    use Archman\ByteOrder\ByteOrder;
    use Archman\ByteOrder\Operator;

    // 假设当前机器为小端64位
    // 127在内中存储方式为: 0x7F 0x00 0x00 0x00 0x00 0x00 0x00 0x00
    // 此方法将转换大端存储,将内存中顺序对调得到: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x7F
    // 即输出为9151314442816847872
    // 大端或32位同理
    $intLE = Operator::transformInt(127, ByteOrder::BIG_ENDIAN);
```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~596 days

Total

3

Last Release

1521d ago

PHP version history (2 changes)v0.1.0PHP &gt;=7.0.0

v0.1.2PHP ^7.0 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8369769?v=4)[Long Haibin](/maintainers/hsldymq)[@hsldymq](https://github.com/hsldymq)

---

Top Contributors

[![hsldymq](https://avatars.githubusercontent.com/u/8369769?v=4)](https://github.com/hsldymq "hsldymq (43 commits)")

---

Tags

byte order

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hsldymq-byte-order-op/health.svg)

```
[![Health](https://phpackages.com/badges/hsldymq-byte-order-op/health.svg)](https://phpackages.com/packages/hsldymq-byte-order-op)
```

###  Alternatives

[archtechx/money

A lightweight package for handling money math in PHP.

171242.9k6](/packages/archtechx-money)[syde/phpcs

Syde PHP coding standards for WordPress projects.

1024.3k8](/packages/syde-phpcs)

PHPackages © 2026

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