I incorporated the binary script into a list of calculator functions to be called upon with buttons in html. The only problem with it is that something I am using is not compatible with Internet-explorer.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
var add = function(){
var one = prompt("enter first number");
one = parseInt(one,10);
var two = prompt("enter second number");
two = parseInt(two,10);
alert(one+two);
return one+two;
};
var subtract = function(){
var one = prompt("enter first number");
one = parseInt(one,10);
var two = prompt("enter second number");
alert(one-two);
return one-two;
};
var multipltwo = function(){
var one = prompt("enter first number");
one = parseInt(one,10);
var two = prompt("enter second number");
two = parseInt(two,10);
alert(one*two);
return one*two;
};
var divide = function(){
var one = prompt("enter first number");
one = parseInt(one,10);
var two = prompt("enter second number");
two = parseInt(two,10);
alert(one/two);
return one/two;
};
var power = function(){
var one = prompt("enter base number");
one = parseInt(one,10);
var two = prompt("enter exponent number");
two = parseInt(two,10);
if(two===0){
alert(1);
return 1;
}
else{
alert(one*two(one,two-1));
return one*two(one,two-1);
}
};
//different part of calculator
var countMult = 1;
var dec = 0;
var convert = function(){
var binartwo = prompt("enter a binartwo number *note antwo number greater than 1 will be seen as a 0*");
var len = binartwo.length;
for (i=0;i<len;i++){
if (binartwo.charAt(len-(i+1)) == 1){
dec+=countMult;
}
countMult = countMult*2;
console.log(dec);
}
alert(dec);
};
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<input type="button" onClick="convert()" value="change a binary number to a decimal number">
</body>
</html>