Download the PHP package riimu/kit-baseconversion without Composer

On this page you can find all versions of the php package riimu/kit-baseconversion. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package kit-baseconversion

Arbitrary Precision Base Converter

BaseConversion is a PHP library for converting number bases, similar to PHP's built in function base_convert(). However, unlike the built in function, this library is not limited by 32 bit integers and is capable of converting numbers of arbitrary precision. This library also supports conversion of fractions and allows more customization in terms of number bases.

In order to optimize the conversion of large numbers, this library also employs two different conversion strategies. In some cases, it's possible to convert numbers simply by replacing the digits with digits from the other base (e.g. when converting from base 2 to base 16). This is considerably faster than the other strategy, which simply calculates the new number using arbitrary precision integer arithmetic.

The API documentation, which can be generated using Apigen, can be read online at: http://kit.riimu.net/api/baseconversion/

Travis Scrutinizer Scrutinizer Coverage Packagist

Requirements

Installation

Installation with Composer

The easiest way to install this library is to use Composer to handle your dependencies. In order to install this library via Composer, simply follow these two steps:

  1. Acquire the composer.phar by running the Composer Command-line installation in your project root.

  2. Once you have run the installation script, you should have the composer.phar file in you project root and you can run the following command:

After installing this library via Composer, you can load the library by including the vendor/autoload.php file that was generated by Composer during the installation.

Adding the library as a dependency

If you are already familiar with how to use Composer, you may alternatively add the library as a dependency by adding the following composer.json file to your project and running the composer install command:

Manual installation

If you do not wish to use Composer to load the library, you may also download the library manually by downloading the latest release and extracting the src folder to your project. You may then include the provided src/autoload.php file to load the library classes.

Usage

The most convenient way to use this library is via the baseConvert() static method provided by the BaseConverter class. In most cases, it works the same way as base_convert() does. For example:

The method accepts negative numbers and fractions in the same way. An optional fourth parameter can be used to define the precision for the conversion. For example:

The static method is simply a convenient wrapper for creating an instance of BaseConvert and calling the setPrecision() and convert() methods. If you need to convert multiple numbers, it's more efficient to call the object in a non static manner. For example:

If the provided number contains invalid digits that are not part of the defined number base, the method will return false instead.

Converting Fractions

While this library does support conversion of fractions, it's important to understand that fractions cannot always be converted accurately from number base to another the same way that integers can be converted. This is result of the fact that not all fractions can be represented in another number base.

For example, let's say we have the number 0.1 in base 3. This equals the same as 1/3 in base 10. However, if you were to represent 1/3 as a decimal number, you would get an infinitely repeating '0.3333...'. For example:

Due to this behavior, it is possible to set the precision used for inaccurate fraction conversions. As can be seen in the previous example, the precision value defines the maximum number of digits in the resulting number. The result may have less digits, however, if the number can be accurately converted using a small number of digits. The precision may also be completely ignored, if the converter knows, that it can accurately convert the fractions.

The precision value also has an alternative definition. If the precision is 0 or a negative number, then the maximum number of digits in the resulting number is based on the precision of the original number. If the precision is 0, the resulting number will have as many digits as it takes to represent the number in the same precision as the original number. A negative number will simply increase the number of digits in addition to that. For example:

In the previous example, the original number is 0.A7 in the base 16. A base 16 number with two digits in the fractional part can represent a number up to accuracy of 1/(16 * 16) == 1/256. To represent the the fractional part in the same accuracy in base 10, we need at least 3 digits, because two digit can only represent numbers up to accuracy of 1/100.

The default precision value used by the library is -1. It is also important to note that the last digit is not rounded (due to the fact that it would cause inconsistent results in some cases).

Case Sensitivity

In order to make user interaction with the library more convenient, the library treats all numbers in a case insensitive manner, unless the number base prohibits that. For example, the base 16 can be treated in a case insensitive manner, because it only defines the value for the digits 0-9A-F. However, base 62 cannot be treated in a case insensitive manner, because letters like A and a have a different value.

The returned numbers will always respect the character case defined by the number base. For example:

Customizing Number Bases

One of the features of this library is that allows much better customization of number bases than base_convert(). In most cases, you will probably define the number base using a simple integer such as 10 or 16. However, there is no limit to the size of that integer. For example:

For large number bases, however, the digits are simply represented by a string that consists of # and the value for the digit. Whenever the number base is defined using an integer, the digits follow the following rules:

In addition to defining the number base using an integer, it's also possible to define the number base using a string. Each character in the string represents a digit and the position of each character represents it's value. The base 16, for example, could be defined as 0123456789ABCDEF. Defining number bases this way also makes it easier to get resulting numbers in a specific case. For example:

There is also a third way to define the number bases using an array. This allows even greater customization in terms of number bases. Each value in the array represents a digit and the index indicates the value. For example:

Credits

This library is Copyright (c) 2013-2017 Riikka Kalliomäki.

See LICENSE for license and copying information.


All versions of kit-baseconversion with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6.0
ext-gmp Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package riimu/kit-baseconversion contains the following files

Loading the files please wait ....