From WikiChip
Editing mirc/identifiers/$base
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
This page supports semantic in-text annotations (e.g. "[[Is specified as::World Heritage Site]]") to build structured and queryable content provided by Semantic MediaWiki. For a comprehensive description on how to use annotations or the #ask parser function, please have a look at the getting started, in-text annotation, or inline queries help pages.
Latest revision | Your text | ||
Line 7: | Line 7: | ||
<span style="display: inline-block; width: 100px;">'''OutBase'''</span>The Number Base to which N is being converted. Can be same as InBase.<br /> | <span style="display: inline-block; width: 100px;">'''OutBase'''</span>The Number Base to which N is being converted. Can be same as InBase.<br /> | ||
<span style="display: inline-block; width: 100px;">'''ZeroPad'''</span>The output's minimum number of non-fraction digits by adding 0's if needed. Accepts up to 100.<br /> | <span style="display: inline-block; width: 100px;">'''ZeroPad'''</span>The output's minimum number of non-fraction digits by adding 0's if needed. Accepts up to 100.<br /> | ||
− | <span style="display: inline-block; width: 100px;">'''Precision'''</span> | + | <span style="display: inline-block; width: 100px;">'''Precision'''</span>The output's maximum number of fraction digits, limited by mIRC's base-10 precision of 6.<br /> |
− | + | * '''Note:''' InBase & Outbase can be any integer from 2-36, with Base 17-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. | |
− | * '''Note:''' InBase & Outbase can be any integer from 2-36, with Base 17-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 | + | * '''Note:''' Prefix 0x or 0X is stripped from N for all bases 2-35 but not base36. To prevent this, such as in base 34-35 where X is a valid character, prefix the input string with 00. |
− | |||
− | * '''Note:''' Prefix 0x or 0X is stripped from N for | ||
* '''Note:''' Base 32 is NOT the same as the base32 encoding method used by $encode(). $base assigns the values 0-31 to characters 0-9 and A-V, while the Base32 encoding method assigns values 0-31 to A-Z and 2-7 then stores them differently. | * '''Note:''' Base 32 is NOT the same as the base32 encoding method used by $encode(). $base assigns the values 0-31 to characters 0-9 and A-V, while the Base32 encoding method assigns values 0-31 to A-Z and 2-7 then stores them differently. | ||
== Properties == | == Properties == | ||
Line 18: | Line 16: | ||
== Example == | == Example == | ||
<source lang="mIRC"> | <source lang="mIRC"> | ||
− | Without changing number base, can use $base to left-zero-pad | + | Without changing number base, can use $base to left-zero-pad or truncate (not round) fractions to fewer digits: |
//echo -a $base(123.456,10,10,6,2) | //echo -a $base(123.456,10,10,6,2) | ||
returns: 000123.45 | returns: 000123.45 | ||
//var %n $color(8) | echo -a %n $base(%n,10,16,6) | //var %n $color(8) | echo -a %n $base(%n,10,16,6) | ||
− | converts the color | + | 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) | //var %n $pi | echo -a %n $base(%n,10,16,0,12) $base($calc(%n * 16^6),10,16,6,12) | ||
Line 39: | Line 37: | ||
</source> | </source> | ||
<source lang="mIRC"> | <source lang="mIRC"> | ||
− | You should not attempt to input numbers greater than decimal 2^53 | + | 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. | $base allows invalid letters to be used in the input, assigning them values as they have in Base 36. | ||
Line 47: | Line 45: | ||
//echo -a $base(mIRC,10,10) is same as $calc(22*1000 + 18*100 + 27*10+ 12*1) | //echo -a $base(mIRC,10,10) is same as $calc(22*1000 + 18*100 + 27*10+ 12*1) | ||
− | The exception to the above is | + | 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. The 0x or 0X prefix is ignored in every base except 36: |
//var %i 2 , %a , %value F | while (%i isnum 2-36) { var %a %a $+(base,%i,=,$base(0x $+ %value,%i,10),vs,$base(%value,%i,10)) | inc %i } | echo -a %a | //var %i 2 , %a , %value F | while (%i isnum 2-36) { var %a %a $+(base,%i,=,$base(0x $+ %value,%i,10),vs,$base(%value,%i,10)) | inc %i } | echo -a %a | ||
− | + | If using base 34 or 35 where X is a valid character, you must prepend the from-value with 00 to prevent 0x from being stripped: | |
− | // | + | //var %value 0xF | echo -a $base(%value,35,10) vs $base(00 $+ %value,35,10) |
− | + | returns: 15 vs 1170 | |
− | To store the 128 hexadecimal digits of the sha512 hash digest in fewer digits, you can't use $base to accurately translate more than 13 digits at a time | + | To store the 128 hexadecimal digits of the sha512 hash digest in fewer digits, you can't use $base to accurately translate more than 13 digits at a time. |
//var %digits 13 , %from_base 16 , %to_base 36 | echo -a $calc( %digits * $log(%from_base) / $log(%to_base) ) | //var %digits 13 , %from_base 16 , %to_base 36 | echo -a $calc( %digits * $log(%from_base) / $log(%to_base) ) | ||
//var %digits 9 , %from_base 16 , %to_base 36 | echo -a $calc( %digits * $log(%from_base) / $log(%to_base) ) | //var %digits 9 , %from_base 16 , %to_base 36 | echo -a $calc( %digits * $log(%from_base) / $log(%to_base) ) | ||
Line 73: | Line 71: | ||
returns: | returns: | ||
shortened 128 d8022f2060ad6efd297ab73dcc5355c9b214054b0d1776a136a669d26a7d3b14f73aa0d0ebff19ee333368f0164b6419a96da49e3e481753e7e96b716bdccb6f to 100 6009P25MYQI73NNEMLHK0MTBF48SUD996MZJE2E6ZVTED4R1VM7E9HEQ5NVGI65GZ6Q7J6FFCCDZ2ZE9413JTJACHSWXJ2SYIR1R | shortened 128 d8022f2060ad6efd297ab73dcc5355c9b214054b0d1776a136a669d26a7d3b14f73aa0d0ebff19ee333368f0164b6419a96da49e3e481753e7e96b716bdccb6f to 100 6009P25MYQI73NNEMLHK0MTBF48SUD996MZJE2E6ZVTED4R1VM7E9HEQ5NVGI65GZ6Q7J6FFCCDZ2ZE9413JTJACHSWXJ2SYIR1R | ||
− | |||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</source> | </source> | ||
− | |||
== Compatibility == | == Compatibility == | ||
{{mIRC compatibility|5.7}} | {{mIRC compatibility|5.7}} | ||
Line 95: | Line 82: | ||
* {{mIRC|$calc}} | * {{mIRC|$calc}} | ||
* {{mIRC|$encode}} | * {{mIRC|$encode}} | ||
− |