PHPackages                             greensea/anybase - 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. greensea/anybase

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

greensea/anybase
================

任意进制转换工具，用于处理各个数位进制不同的数字

04PHP

Since Jun 16Pushed 3y ago1 watchersCompare

[ Source](https://github.com/greensea/anybase)[ Packagist](https://packagist.org/packages/greensea/anybase)[ RSS](/packages/greensea-anybase/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

anybase
=======

[](#anybase)

任意进制转换工具，用于处理各个数位进制不同的数字

用法
--

[](#用法)

```
$id = 234;
$cardinals = [10, 10, 10];
print_r(AnyBase::convert($id, $cardinals));
// 输出：[2, 3, 4]

```

说明
--

[](#说明)

这原本是一个用来处理 NFT trait 组合的工具。在 trait 集合确定的情况下，给定一个组合，可以唯一确定一个编号；给定一个编号，可以唯一确定一个组合。

假设，我们有眼睛 3 个，鼻子 2 个，嘴巴 4 个，那么 基数列表（cardinals）为：`[3, 2, 4]`我们最多可以组成 `3 * 2 * 4 = 24` 个图像，因此，我们可以给这些图像使用 \[0, 23\] 进行编号。 给定一个编号，我们可以唯一确定一个组合。同时，一个组合亦可唯一确定一个编号。

我们定义一个三位数，但每一位的进制不同，眼睛、鼻子和嘴巴各代表一位，表示出来即： \[眼睛\]\[鼻子\]\[嘴巴\] 其中\[眼睛\]位逢三进一，\[鼻子\]位逢二进一，\[嘴巴\]位逢四进一 于是我们就可以轻松地使用进制转换方法来对编号和组合进行互换了

### 编号确定方法

[](#编号确定方法)

例如，我们想用第 0 个眼睛，第 1 个鼻子，第 2 个嘴巴组成图片，则编号可以计算为（编号从 0 开始）：

```
 0 * (2*4) + 1 * 4 + 2 = 0 + 4 + 2 = 6
眼睛         鼻子    嘴巴

```

得编号 6.

### 组合确定方法

[](#组合确定方法)

给定一个编号，例如 15，我们分解这个编号为：

\[眼睛\] = `15 / (2 * 4) = 1 余 7`，即眼睛编号为 1 \[嘴巴\]:

```
      15 -       (2 * 4)1 = 7
            鼻子基数*眼睛基数  眼睛编号
      7 / (4) = 1 余 3，即嘴巴编号为 1

```

\[鼻子\]:

```
      7 - (4) * 1 = 3
      即鼻子编号为 3

```

### 上面两个例子的测试结果

[](#上面两个例子的测试结果)

```
$cardinals = [3, 2, 4];
$ids = [1, 1, 3];
$foo = AnyBase::extract(6, $cardinals);
print_r($foo);
/// 输出 [0, 1, 2]

```

```
$cardinals = [3, 2, 4];
$ids = [1, 1, 3];

echo AnyBase::convert($ids, $cardinals);
/// 输出 15

```

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity25

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/135ae539aa14fcf702ba4f81b38730d456ba96a7a31fef91c4a0abefa9e00717?d=identicon)[greensea](/maintainers/greensea)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/greensea-anybase/health.svg)

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

PHPackages © 2026

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