A collection of useful static methods to deal with numeral system.
A numeral system is a writing system for expressing numbers; that is, a mathematical notation for representing numbers of a given set, using digits or other symbols in a consistent manner.
- Since:
- 3.1.0
- See:
Methods
(static) convert(value, from, toopt) → {String}
Returns a string representation of the first argument in the radix specified by the third argument from the radix specified by the second argument.
For radixes above 10
, the letters of the alphabet indicate numerals greater than 9
. For
example, for hexadecimal numbers (base 16), a
through f
are used.
If the third argument is not specified, the preferred radix is assumed to be 10.
If the first argument is negative, the sign is preserved. This is the case even if the radix is 2
;
the string returned is the positive binary representation of the first argument preceded by a -
sign,
not the two's complement of the first argument.
If the first argument is not a whole number, the 'dot' sign is used to separate the decimal places.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
value |
Object | to be converted to the desired system. |
||
from |
Number | the radix to which the string representation is in. |
||
to |
Number |
<optional> |
10 | the radix to use in the string representation. |
- Since:
- 3.1.0
Throws:
-
If radix is not between
2
and36
. - Type
- RangeError
Returns:
a string representation of the argument in the specified radix.
- Type
- String
(static) convertBinaryToDecimal(obj) → {String}
Returns a string representation of the binary value in base 10.
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object | binary value to be converted to a string. |
- Since:
- 3.1.0
Returns:
the string representation in decimal (base 10).
- Type
- String
(static) convertBinaryToHexadecimal(obj) → {String}
Returns a string representation of the binary value in base 16.
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object | binary value to be converted to a string. |
- Since:
- 3.1.0
Returns:
the string representation in hexadecimal (base 16).
- Type
- String
(static) convertBinaryToOctal(obj) → {String}
Returns a string representation of the binary value in base 8.
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object | binary value to be converted to a string. |
- Since:
- 3.1.0
Returns:
the string representation in octal (base 8).
- Type
- String
(static) convertDecimalToBinary(obj) → {String}
Returns a string representation of the decimal value in base 2.
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object | decimal value to be converted to a string. |
- Since:
- 3.1.0
Returns:
the string representation in binary (base 2).
- Type
- String
(static) convertDecimalToHexadecimal(obj) → {String}
Returns a string representation of the decimal value in base 16.
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object | decimal value to be converted to a string. |
- Since:
- 3.1.0
Returns:
the string representation in hexadecimal (base 16).
- Type
- String
(static) convertDecimalToOctal(obj) → {String}
Returns a string representation of the decimal value in base 8.
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object | decimal value to be converted to a string. |
- Since:
- 3.1.0
Returns:
the string representation in octal (base 8).
- Type
- String
(static) convertHexadecimalToBinary(obj) → {String}
Returns a string representation of the hexadecimal value in base 2.
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object | hexadecimal value to be converted to a string. |
- Since:
- 3.1.0
Returns:
the string representation in binary (base 2).
- Type
- String
(static) convertHexadecimalToDecimal(obj) → {String}
Returns a string representation of the hexadecimal value in base 10.
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object | hexadecimal value to be converted to a string. |
- Since:
- 3.1.0
Returns:
the string representation in decimal (base 10).
- Type
- String
(static) convertHexadecimalToOctal(obj) → {String}
Returns a string representation of the hexadecimal value in base 8.
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object | hexadecimal value to be converted to a string. |
- Since:
- 3.1.0
Returns:
the string representation in octal (base 8).
- Type
- String
(static) convertOctalToBinary(obj) → {String}
Returns a string representation of the octal value in base 2.
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object | octal value to be converted to a string. |
- Since:
- 3.1.0
Returns:
the string representation in binary (base 2).
- Type
- String
(static) convertOctalToDecimal(obj) → {String}
Returns a string representation of the octal value in base 10.
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object | octal value to be converted to a string. |
- Since:
- 3.1.0
Returns:
the string representation in decimal (base 10).
- Type
- String
(static) convertOctalToHexadecimal(obj) → {String}
Returns a string representation of the octal value in base 16.
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object | octal value to be converted to a string. |
- Since:
- 3.1.0
Returns:
the string representation in hexadecimal (base 16).
- Type
- String