View Single Post
Old 03-02-2008, 09:34   #20 (permalink)
proc355
Senior Member
 
proc355's Avatar
 
Join Date: Sep 2006
Location: Glasvegas
Posts: 865
Quote:
Originally Posted by haku
Nice little piece of code Proc.
cheers

even tighter…
Code:
<html> <head> <script type="text/javascript"> function pad(s,l){var p=s,i=l-s.length;do{p="0"+s;}while(i--);return p;} function marshal(s){ var m="",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="",i=s.length; do{var c=s[i-2]+s[i-1];d=(c[0]==0?c[1]:String.fromCharCode(c))+d;}while(i-=2); return d; } function testme(){ alert(marshal("12AB")); alert(demarshal(pad("1026566", 8))); alert(marshal("FOOBAR69")); alert(demarshal("7079796665820609")); } </script> </head> <body onload="testme()"> </body> </html>

obviously counting to 2 was beyond me the other morning.
__________________
meh.

Last edited by proc355 : 21-09-2008 at 14:28.
  Reply With Quote