定制 carrontiger/conversion 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

carrontiger/conversion

Composer 安装命令:

composer require carrontiger/conversion

包简介

Conversion from/to decimal numerals.

README 文档

README

Conversion from/to decimal numerals

Comparison of Converters

Examples

Converter Result of toDecimal() Result of fromDecimal()
BinaryConverter 2147483647 1111111111111111111111111111111
OctalConverter 2147483647 17777777777
HexadecimalConverter 2147483647 7FFFFFFF
CaseInsensitiveAlphaDecimalConverter 2147483647 ZIK0ZJ
CaseSensitiveAlphaDecimalConverter 2147483647 2LKcb1
AsciiDecimalConverter 2147483647 Rll}&

Meta Information

Converter Base “Digits”
BinaryConverter 2 01
OctalConverter 8 01234567
HexadecimalConverter 16 0123456789ABCDEF
CaseInsensitiveAlphaDecimalConverter 36 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
CaseSensitiveAlphaDecimalConverter 62 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
AsciiDecimalConverter 94 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~

Individual Examples

Binary Numerals

Conversion of decimal numeral to a binary numeral
use carrontiger\Conversion\BinaryConverter;

$binaryConverter = new BinaryConverter();

echo $binaryConverter->fromDecimal(123);
//  "01111011"
Conversion of binary numeral to a decimal numeral
use carrontiger\Conversion\BinaryConverter;

$binaryConverter = new BinaryConverter();

echo $binaryConverter->toDecimal('01111011');
//  123

Octal Numerals

Conversion of decimal numeral to a octal numeral
use carrontiger\Conversion\OctalConverter;

$octalConverter = new OctalConverter();

echo $octalConverter->fromDecimal(123);
//  "173"
Conversion of octal numeral to a decimal numeral
use carrontiger\Conversion\BinaryConverter;

$octalConverter = new OctalConverter();

echo $octalConverter->toDecimal('173');
//  123

Hexadecimal Numerals

Conversion of decimal numeral to a hexadecimal numeral
use carrontiger\Conversion\HexadecimalConverter;

$hexadecimalConverter = new HexadecimalConverter()

echo $hexadecimalConverter->fromDecimal(123);
//  "7B"
Conversion of hexadecimal numeral to a decimal numeral
use carrontiger\Conversion\HexadecimalConverter;

$hexadecimalConverter = new HexadecimalConverter();

echo $hexadecimalConverter->toDecimal('7B');
//  123

Case-Insensitive Alpha-Decimal Numerals

The case-insensitive alpha-decimal numeral encoding uses the following 36 “digits”:

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ

Conversion of decimal numeral to a case-insensitive alpha-decimal numeral
use carrontiger\Conversion\CaseInsensitiveAlphaDecimalConverter;

$ciAlphaDecimalConverter = new CaseInsensitiveAlphaDecimalConverter()

echo $ciAlphaDecimalConverter->fromDecimal(123);
//  "3F"
Conversion of a case-insensitive alpha-decimal numeral to a decimal numeral
use carrontiger\Conversion\CaseInsensitiveAlphaDecimalConverter;

$ciAlphaDecimalConverter = new CaseInsensitiveAlphaDecimalConverter();

echo $ciAlphaDecimalConverter->toDecimal('3F');
//  123

Case-Sensitive Alpha-Decimal Numerals

The case-sensitive alpha-decimal numeral encoding uses the following 62 “digits”:

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

Conversion of decimal numeral to a case-sensitive alpha-decimal numeral
use carrontiger\Conversion\CaseSensitiveAlphaDecimalConverter;

$alphaDecimalConverter = new CaseSensitiveAlphaDecimalConverter()

echo $alphaDecimalConverter->fromDecimal(123);
//  "1z"
Conversion of a case-sensitive alpha-decimal numeral to a decimal numeral
use carrontiger\Conversion\CaseSensitiveAlphaDecimalConverter;

$alphaDecimalConverter = new CaseSensitiveAlphaDecimalConverter();

echo $alphaDecimalConverter->toDecimal('1z');
//  123

ASCII-Numerals

The ASCII numeral encoding uses the following 94 “digits”:

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!"#$%&'()*+,-./:;<=>?@[\]^_`{\|}~

Due to the use of non-alphabetic characters, it is not practical for ASCII numerals to be embedded in texts or be used as plain HTTP query arguments, for example. One purpose would be to encode large integer numbers, compactly. But most of all, this is an example of an arbitrary numeral system, than one can define.

If you were to define a numeral system (by extending the AbstractDecimalConverter class), be advised, to use only one-byte characters as digits.

Conversion of decimal numeral to an ASCII numeral
use carrontiger\Conversion\AsciiDecimalConverter;

$asciiDecimalConverter = new AsciiDecimalConverter()

echo $asciiDecimalConverter->fromDecimal(123);
//  "1T"
Conversion of an ASCII numeral to a decimal numeral
use carrontiger\Conversion\AsciiDecimalConverter;

$asciiDecimalConverter = new AsciiDecimalConverter()

echo $asciiDecimalConverter->toDecimal('1T');
//  123

carrontiger/conversion 适用场景与选型建议

carrontiger/conversion 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 04 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 carrontiger/conversion 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 carrontiger/conversion 我们能提供哪些服务?
定制开发 / 二次开发

基于 carrontiger/conversion 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2024-04-07