Difference between revisions of "$base"

From Scriptwiki
Jump to: navigation, search
 
m (Category)
 
Line 16: Line 16:
 
To convert 255 (decimal, 10) to hexadecimal (base 16):
 
To convert 255 (decimal, 10) to hexadecimal (base 16):
 
  $base(255,10,16) -> FF
 
  $base(255,10,16) -> FF
 +
 +
[[Category:Text and Number Identifiers]]

Latest revision as of 22:31, 17 February 2008

Base allows you to change the radix of a number, up to base 36. The limit is base 36 because the only characters which are supported are A-Z and 0-9, 36 total.

$base(N,inbase,outbase,[zeropad],[precision])
  • N is the number to change the base of.
  • inbase is the radix of N currently.
  • outbase is the radix you wish to change N to, from inbase.
  • zeropad is the number of digits the final result should be. If the result is less than zeropad digits in length, 0s are added to the front of the result. If the result is greater than zeropad digits, it is all returned.
  • precision is the number of decimals to return.

Base 10 is the common decimal numbering system most people use.

Example

To convert 255 (decimal, 10) to binary (base 2):

$base(255,10,2) -> 11111111

To convert 255 (decimal, 10) to hexadecimal (base 16):

$base(255,10,16) -> FF