function replac(a){
var z = '00000000';
var Len=a.split("").length;
a=z.substring(0,8-Len)+a;
return a;
}
//=============
var R = ("9");
var R1=R.charCodeAt();
var R2=255-R1;
alert(replac(R1.toString(2))+'\n'+replac(R2.toString(2))+'\n\n'+R1.toString(16)+'\n'+R2.toString(16));