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 9: Line 9:
 
<span style="display: inline-block; width: 100px;">'''Precision'''</span>Shortens the output's maximum number of fraction digits, limited by mIRC's base-10 precision of 6.<br />
 
<span style="display: inline-block; width: 100px;">'''Precision'''</span>Shortens the output's maximum number of fraction digits, limited by mIRC's base-10 precision of 6.<br />
  
* '''Note:''' Beginning v7.72 $base supports the larger integer accuracy of bigfloat mode without needing to use %varname.bf or /bigfloat on, and no longer limits zero padding to 100 digits. But extra precision for fractional input requires bigfloat mode.
 
 
* '''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 accept case-insensitive input, but always outputs uppercase.
 
* '''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 accept case-insensitive input, but always outputs uppercase.
* '''Note:''' All 36 inbases accept all 36 characters of the base36 alphabet, so $base(ZZ,2,10) = 35*2+35=105.
+
* '''Note:''' Prefix 0x or 0X is stripped from N for base 16. (Prior to v7.53 only base36 did not strip the 0x. To prevent this, such as in base 34-35 where X is a valid character, it was necesary to prefix the input string with 00.)
* '''Note:''' Prefix 0x or 0X is stripped from N for base 16. (Prior to v7.53 only base36 did not strip the 0x. To prevent this, such as in base 34-35 where X is a valid character, it was necesary to prefix inputs with 00.)
 
 
* '''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 39: Line 37:
 
</source>
 
</source>
 
<source lang="mIRC">
 
<source lang="mIRC">
You should not attempt to input numbers greater than decimal 2^53 prior to v7.72. For N=1+2^n, this shows that even though $base failed to convert back to the original number starting with N=55, $calc failed to create an odd-numbered number at N=53. But starting v7.72 the $base output is accurate as long as the input is too
+
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.
  
//if ($version >= 7.72) bigfloat on | 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 }
+
//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 55: Line 53:
 
returned: 15 vs 1170
 
returned: 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, until v7.72.
+
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>
 
 
But beginning v7.72 the above is not needed as the accurate results are obtained from both:
 
<source lang="mIRC">
 
//echo -a $base($base($sha1(abc),16,10),10,16) is A9993E364706816ABA3E25717850C26C9CD0D89D
 
//echo -a $base($sha1(abc),16,36) is JT72FO5T4YOBF0QUGWUCZBWJ07MAX7H
 
</source>
 
starting v7.72 the accuracy for large integers is always enabled by default, but precision for fractions is only enabled if in bigfloat mode:
 
<source lang="mIRC">
 
//var -s %var.bx 10000000000000000000000000001 | echo -a $base(%var.bx,10,10)
 
result: 10000000000000000000000000001
 
//var -s %var.bf 0.10000000000000000000000000001 | echo -a $base(%var.bf,10,10)
 
result: 0.10000000000000000000000000001
 
//var -s %var.bx 0.10000000000000000000000000001 | echo -a $base(%var.bx,10,10)
 
result: 0.1
 
 
</source>
 
</source>
  

Please note that all contributions to WikiChip may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see WikiChip:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)