baseConvert | |||||||||||||
Type | function | ||||||||||||
Dictionary | LCS | ||||||||||||
Library | LiveCode Script | ||||||||||||
Syntax |
| ||||||||||||
Summary | Converts a number from one base to another. | ||||||||||||
Introduced | 1.0 | ||||||||||||
OS | mac, windows, linux, ios, android | ||||||||||||
Platforms | desktop, server, mobile | ||||||||||||
Parameters |
| ||||||||||||
Example |
| ||||||||||||
Values |
| ||||||||||||
Related | Property: convertOctals Operator: bitNot Function: exp, URLDecode, format Glossary: binary, hexadecimal, return | ||||||||||||
Description | Use the baseConvert function to provide input or output of numbers in a base other than base 10: for example, in hexadecimal (base 16) or binary (base 2). The everyday decimal number system is called "base 10" because we count from 1 to 9, and the tenth digit moves over to the tens place and is written 10: one group of ten, plus zero extra ones. Similarly, a number like 384 means one group of a hundred (10^2), plus eight groups of ten, plus four leftover ones. It is possible to write numbers in other bases. For example, suppose you want to write the number six in base 4. In base 4, we count from 1 to 3, and the fourth digit moves over to the "fours place". So the numbers from one to six, in base 4, are written "1, 2, 3, 10, 11, 12". The number 12 in base 4 means one group of four, plus two leftover ones. This same number is written as 6 in base 10. If the base is greater than 10, then digits greater than 9 are expressed as capital letters: A is the digit ten, B is the digit eleven, and so on. LiveCode always does math in base 10, so if you want to perform mathematical calculations such as addition on a number in another base, you must first convert the number to base 10, do the calculation, then convert back to the original base. Here is an example:
| ||||||||||||
Tags | math |