ну если так нужны функции то вот:
function toBIN( num ) {
var out = "", bit = 1;
while( num >= bit ) {
out = ( num & bit ? 1 : 0 ) + out;
bit <<= 1;
}
return out || "0";
}
alert( toBIN(20) );
function toDEC( dec ) {
var out = 0, len = dec.length, bit = 1;
while( len-- ) {
out += dec[ len ] == "1" ? bit : 0;
bit <<= 1;
}
return out;
}
alert( toDEC( '10100' ) );