choval/base_convert 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

choval/base_convert

Composer 安装命令:

composer require choval/base_convert

包简介

A base convert functino for converting extra large numbers from one base to another

README 文档

README

A base_convert replacement that doesn't lose precision on large numbers.

A few differences from this convert:

  • Second and third parameters (bases) accept:
    • an int between 2 and 64 (0-9a-zA-Z-_)
    • a string of unique characters
    • an array of unique characters
  • A fourth parameter allows passing a padding length for the output
  • A fifth parameter can be passed to be used as the padding character, else the first char of the base is used.

Negative numbers are converted to positive, just like base_convert.

Install

This function uses the GMP or the BCMath extension. Install one of them.

apt install php-gmp
apt install php-bcmath

Uses GMP > BCMath > PHP. If vanilla PHP, a E_USER_WARNING is triggered.

To Install this library:

composer require choval/base_convert

Usage

Procedural:

use function Choval\base_convert;
echo base_convert(1000, 10, 16);
// 3e8

Object:

use Choval\BaseConvert;
echo BaseConvert::from(1000)->to(16);
// 3e8

echo BaseConvert::from('3e8', 16)->to(64);
// fE

Padding:

$base = 'abcdefghijklmnopqrstuvwxyz';

echo BaseConvert::from(1000)->to($base);
// bmm

echo BaseConvert::from(1000)->to($base, 10);
// aaaaaaabmm

echo BaseConvert::from(1000)->to($base, 10, '#');
// #######bmm

echo base_convert(1000, 10, $base, 10, '#');
// #######bmm

echo BaseConvert::from('#######bmm', $base)->to(10);
// 1000

echo base_convert('#######bmm', $base, 10);
// 1000

Keep in mind the type of the parameters, '10' and 10 are not the same.

$base = 'abcdefghijklmnopqrstuvwxyz';

echo BaseConvert::from('bmm', $base)->to(10);
// 1000

echo BaseConvert::from('bmm', $base)->to('10');
// 0000010111

echo BaseConvert::from('bmm', $base)->to('01');
// 1111101000

echo BaseConvert::from('bmm', $base)->to(2);
// 1111101000

License

MIT, see LICENSE

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-08-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固