4. Number formats

What are number formats?

Number formats are different ways to write down a number in DestinyScript. There are 4 formats total to write down a number in DestinyScript. Three of them are known from computer science. The other format is used for our known decimal system. If we write down a number then we usually use one of the 10 digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9). Because we have 10 digits the base of this number system is 10. If we read a number then we multiply each digit with the base exponentiated by the digit index minus 1.
In this example the circumflex is used as symbol for the exponentation.
123 = 1 * 10 ^ 2 + 2 * 10 ^ 1 + 3 * 10 ^ 0
123 = 1 * 100 + 2 * 10 + 3 * 1
123 = 100 + 20 + 3
123 = 123
A translation of a number from the decimal system into the decimal system meaningless, because the result will always be the same. However if we use two different number systems (number systems with different bases) then we get differing results. First we use the hexadecimal system. It contains 16 digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F). The digits A to F equates to the numbers 10 to 15. For example: 1AB is a valid hexadecimal number. Translated into the decimal system it is:
In this example the circumflex is used as symbol for the exponentation.
1AB (hex) = 1 * 16 ^ 2 + 10 * 16 ^ 1 + 11 * 16 ^ 0 (dec)
1AB (hex) = 1 * 256 + 10 * 16 + 11 * 1 (dec)
1AB (hex) = 256 + 160 + 11 (dec)
1AB (hex) = 427 (dec)
It seems to be meaningless for the layman, but for the expert it is very helpful. If we write down such numbers we find a drastic problem: Some numbers can't be clearly related to a specific number system. For example the number 10 in hexadecimal is not the same as the number 10 in decimal. Hence we must cleary define which number system we use. So we append a 0x as identifier in DestinyScript at the beginning of a hexadecimal number (e. g. 0x123 = 291). Something similar is used for the other number formats octal (Base: 8, Digits: 0-7, Identifier: 0o) and binary (Base: 2, Digits: 0 and 1, Identifier: 0b). For decimal numbers are no identifiers used. An important note is still that floating point numbers can only be used in the decimal number format. The point is used as decimal separator (e. g. 1.5 is a valid floating point number).

List of number formats

DestinyScript supports 4 different number formats
Number formatBaseFloating point numberIdentifierExamples
Decimal10yesnone11, 9, 10.6, 3.1415926535
Hexadecimal16no0x0x10, 0xAC, 0x1237
Octal8no0o0o17, 0o32, 0o700
Binary2no0b0b111011, 0b00111101, 0b1111110
Information
If we try to write down a floating point number in a different number format than the decimal system then an error occurs (e. g. 0x11.5 isn't a valid number).

Differently calculation of integers and floating point numbers

First of all we have the following example:
1
2
3
$
f[1] = 3 / 2;
f[2] = 3.0 / 2.0
You could anticipate that f[1] and f[2] are equal at the end of the script, but in fact they are different: f[1] whould be 1 and f[2] whould be 1.5 at the end of the script. This difference occurs because we defined each number in line 2 as integer values. So they are divided like integers (integers don't have decimal places - hence they are not calculated). In line 3 instead we defined each number as floating point number. Hence they are calculated like floating point numbers (the decimal places are not lost). You should notice this difference if you want to calculate with floating point numbers.