ok i proofed this last night—there isn't much in it—but have been fiddling around with it trying to squeeze every last drop of speed out of it/minimise the footprint (don't ask me why, it just piqued my interest & i haven't been playing with any
actual javascript lately)
anyway, can't seem to get better than this (golfed to death where line length is less than 80 chars)
Code:
///////////////////////////////////////////////////////////////////////////////
//
// methods to [de]marshal alphanumeric [<]=> numeric string
//
// A-Z !a-z - if you need lcase you'll need another leading 0 et al...
// ...you're already doubling up on your storage doing this
//
// all methods take & return a string
// pad also takes the desired length
//
function pad(s,l){var p=s;var i=l-s.length;do{p='0'+s;}while(i--);return p;}
function marshal(s){
var m='';
var i=s.length-1;
do{var c=s[i];m=(c.match(/[0-9]/)?'0'+c:c.charCodeAt(0))+m;}while(i--);
return m;
}
function demarshal(s){
var d='';
for (var i=s.length;i>-1;i-=2){
var c=s[i]+s[i+1];
d=(c[0]==0?c[1]:String.fromCharCode(c))+d;
}
return d;
}
// test
alert( marshal('12AB') ); //-> 01026566
alert( demarshal( pad('1026566', 8) ) ); //-> 12AB
alert( marshal('FOOBAR69') ); //-> 7079796665820609
alert( demarshal('7079796665820609') ); //-> FOOBAR69
//
//
///////////////////////////////////////////////////////////////////////////////
__________________meh.