Download the PHP package ocubom/base-convert without Composer
On this page you can find all versions of the php package ocubom/base-convert. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ocubom/base-convert
More information about ocubom/base-convert
Files in ocubom/base-convert
Package base-convert
Short Description Safe number conversion between arbitrary bases.
License MIT
Homepage http://github.com/ocubom/base-convert
Informations about the package base-convert
Contents
* [About](#about-base-convert) * [Getting Started](#getting-started) * [Installation](#installation) * [Usage](#usage) * [Roadmap](#roadmap) * [Contributing](#contributing) * [Authorship](#authorship) * [License](#license)About Base Convert
Base Convert performs safe number conversion between arbitrary bases. The conversion is performed with a custom implementation to avoid native PHP base_convert function float precision problem.
The implementation used is extracted from the Symfony UID component.
The class BinaryUtil
implements the necessary fromBase
and toBase
methods.
These methods have been extracted to ensure compatibility (it is an internal class) and to reduce the minimum PHP version requirement.
Getting Started
Installation
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Usage
Just use like the native base_convert. Although the implementation is compatible with native conversion it provides some improvements:
-
Bases can be between 2 and 62. The native version only supports bases between 2 and 36.
The conversion uses Base62 in the same manner as the GMP extension. The conversions are compatible.
-
"Named bases" are supported.
Name Base dec
base-10 hex
base-16 oct
base-8 -
The special base
bin
can be used to convert from/to binary strings. This can be used to directly convert binary outputs of some functions.Warning
Do not confuse a binary encoding (
bin
) with the Base2 encoding (a text string with the characters0
and1
).In PHP there are several functions:
-
bin2hex/hex2bin that convert between hexadecimal and binary.
- bindec/decbin that convert between Base2 and Base10.
In this library the string
bin
has been considered to be equivalent to the first set of functions. -
-
New bases can be used by implementing the base interface.
Includes bases for Douglas Crockford Base32 and Satoshi Nakamoto Base58 encodings. The implementations are examples of how to customize your own encoding.
Douglas Crockford Base 32 encoding
A secure version of the Base 32 encoding proposed by Douglas Crockford.
Note
The encoding scheme is required to
Be human-readable and machine-readable.
Be compact. Humans have difficulty in manipulating long strings of arbitrary symbols.
Be error resistant. Entering the symbols must not require keyboarding gymnastics.
- Be pronounceable. Humans should be able to accurately transmit the symbols to other humans using a telephone.
-- Douglas Crockford. Base 32
This encoding is accessible:
-
By passing a
Crockford
object as any of the base arguments of thebase_convert
function. -
Using the
encode
anddecode
methods of theCrockford
class. - Using the
crockford_encode
andcrockford_decode
functions.
An additional parameter can be added to include a checksum for error detection.
Satoshi Nakamoto Base 58 encoding
Bitcoin addresses use a variant of Base 64 that omits characters that can lead to confusion. The result is a Base 58 encoding.
Note
Why base-58 instead of standard base-64 encoding?
Don't want 0OIl characters that look the same in some fonts and could be used to create visually identical looking data.
A string with non-alphanumeric characters is not as easily accepted as input.
E-mail usually won't line-break if there's no punctuation to break at.
- Double-clicking selects the whole string as one word if it's all alphanumeric.
-- Satoshi Nakamoto. Bitcoin source code
This encoding is accessible by passing a Base58
object as any of the base arguments of the base_convert
function.
Roadmap
See the open issues for a full list of proposed features (and known issues).
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
- Fork the Project.
- Create your Feature Branch (
git checkout -b feature/your-feature
). - Commit your Changes (
git commit -m 'Add your-feature'
). - Push to the Branch (
git push origin feature/your-feature
). - Open a Pull Request.
Authorship
- Oscar Cubo Medina — https://ocubom.github.io
See also the list of contributors who participated in this project.
License
Distributed under the MIT License. See LICENSE for more information.
"PHP base_convert"
"Douglas Crockford's Base32 Encoding"
"PHP Floating point numbers"
"PHP GMP extension"
"PHP bin2hex"
"PHP hex2bin"
"PHP bindec"
"PHP decbin"