Posted: Tue Jan 08, 2008 1:34 am
Kieran Huggins wrote:his only goes up to base 62!
Code: Select all
c = (c || "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")Anyway - I'm glad I've found this site - great scripts
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Kieran Huggins wrote:his only goes up to base 62!
Code: Select all
c = (c || "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")Code: Select all
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"Only the default value is 62 chars long ...Help
Methods
Number.toBase(base: Integer, [charset: String = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"]): String
Encodes an integer number into string.
base
base that will be used to encode the number (from 2 to charset.length)
charset
set of characters that will be used in the encoding
String.parseInt(base: Integer, [charset: String = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"]): Integer
Decodes a string into an integer number.
base
base that will be used to decode the number (from 2 to charset.length)
charset
set of characters that will be used in the decoding
Code: Select all
function a(b)
{
b = b || 10;
..............
}
Code: Select all
function a($b = 10)
{
................
}Code: Select all
var toBase = function (base,fromBase)
{
var symbolSheet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/".split("");
if (typeof fromBase != "undefined")
{
var decimal = 0;
for (var i=0; i < this.toString().length; i++)
{
decimal = decimal + (Math.pow(fromBase,i) * symbolSheet.toString().replace(',','','g').indexOf(this.toString().charAt(this.toString().length-(i+1))));
}
}
else
{
var decimal = this;
}
var conversion = "";
if (base > symbolSheet.length || base <= 1)
{
return false;
}
while (decimal >= 1)
{
conversion = symbolSheet[(decimal - (base*Math.floor(decimal / base)))] +conversion;
decimal = Math.floor(decimal / base);
}
return (base<11) ? parseInt(conversion): conversion;
}
String.prototype.toBase = toBase, Number.prototype.toBase = toBase;
delete toBase;Code: Select all
"a".toBase(10);
//or
(10).toBase(64);
Any ideas?TypeError: "a".toBase is not a function
or
TypeError: (10).toBase is not a function