number_system

A package to extend the functionality to convert between number systems

Hecho en 🇵🇷 por Radamés J. Valentín Reyes

Importing library

import 'package:number_system/number_system.dart';

Note

Rather than the functionality being provided as normal functions it is provided as Extensions so that functions are available through dot notation on valid types.

Examples

Hexadecimal to decimal

Returns the integer value of a hexadecimal String. Extension for String type.

String testString = "#f32";
print("$testString = ${testString.hexToDEC()}");

Decimal to hexadecimal

Returns a String representing the integer in hexadecimal. Extension for int type.

int testInteger = 1667;
print("$testInteger in hex is ${testInteger.decToHex()}");

Desired digits test on decimal to hexadecimal

Decimal to hexadecimal example containing the optional parameter called desired digits. If the resulting hexadecimal value is smaller than the desired digits value 0s will be added to the left side of the number to return a number with the desired length. Extension for int type.

int testInteger = 1667;
print("$testInteger in hex is ${testInteger.decToHex(4)}");

Decimal to octal

Calculates and returns the octal value of this integer

int testInteger = 1667;
print("$testInteger in octal is ${testInteger.decToOctal()}");

Octal to decimal

Calculate and return the decimal value of this octal integer

int testInteger = 3203;
print("$testInteger in decimal is ${testInteger.octalToDec()}");

Binary to decimal

Calculate and return the decimal value of this binary number(string)

String bin = "10";
print(bin.binaryToDec());

Decimal(integer) to binary

Calculate and return the binary value of this integer

int dec = 5;
print(dec.decToBinary());

Contribute/donate by tapping on the Pay Pal logo/image


References

Libraries

number_system