The $base identifier converts numbers between different number bases, or zero-pads numbers to the desired length.
Synopsis
$base(<N>,<InBase>,<OutBase>[,Zero-pad][,Precision])
Parameters
NThe Number being converted.
InBaseThe Number Base in which N is being expressed.
OutBaseThe Number Base to which N is being converted. Can be same as InBase.
ZeroPadThe output's minimum number of non-fraction digits by adding 0's if needed. Accepts up to 100.
PrecisionThe output's maximum number of fraction digits, limited by mIRC's base-10 precision of 6.
Note: InBase & Outbase can be any integer from 2-36, with Base 16-36 extending hexadecimal to use as many letters as needed from the G-Z range. Letters A-Z used by number bases 11 through 36 are case-insensitive.
Properties
None
Example
//var %n $color(8) | echo -a %n $base(%n,10,16,6) ; converts the {{mIRC|$color}} number for yellow from decimal to hexadecimal, zero padded to 6 digits. ; Output is 00FFFF not FFFF00 because mIRC stores colors as GBR not RGB.
//var %n $pi | echo -a %n $base(%n,10,16,0,12) $base($calc(%n * 16^6),10,16,6,12) ; returns: 3.14159265358979323846 3.243F7 3243F6A.8885A ; precision of output is input's limit of 6 fraction digits
//var %n $crc(abc,0) | echo -a %n $base(%n,16,36,7) ; Converts 8-digit hexadecimal ; Base 36 extends the hexadecimal alphabet so the last character Z has decimal value 35
//var %n $str(F,9) | echo -a converts 9-digit hex number %n to 7-digit base-36 $base(%n,16,36,7) ; returns: converts 9-digit hex number FFFFFFFFF to 7-digit base-36 VKHSVLR
You should not attempt to input numbers greater than decimal 2^53. For N=1+2^n, this shows that even though $base fails to convert back to the original number starting with N=55, $calc failed to create an odd-numbered number at N=53.
//var %i 1 | while (%i isnum 1-64) { var %n $calc(1+2^%i ) | echo -a %i %n $base(%n,10,16) $base($base(%n,10,16),16,10) | inc %i }
$base allows invalid letters to be used in the input, assigning them values as they have in Base 36.
//echo -a $base(mIRC,10,10) is same as $calc(22*1000 + 18*100 + 27*10+ 12*1)
The exception to the above is recognizing the 0x prefix for hexadecimal notation. Converting from base-16 to base1- results in 255 for both 0xFF and FF.
Compatibility
Added: mIRC v5.7
Added on: 02 Feb 2000
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.