How do I make this array work properly. It is to convert binary to decimal then add them. The example I have written works but I know its not proper for the array as I would like to use a loop with the array to solve the problem
Code:
<html>
<head>
<script type="text/javascript">
function sum(a,b)
{
var c = a.split("");
var d = b.split("");
var e;
var f;
var answer3;
e = c[0] * 128 + c[1] * 64 + c[2] * 32 + c[3] * 16 + c[4] * 8 + c[5] * 4 + c[6] * 2 + c[7] * 1;
f = d[0] * 128 + d[1] * 64 + d[2] * 32 + d[3] * 16 + d[4] * 8 + d[5] * 4 + d[6] * 2 + d[7] * 1;
answer3 = e + f
document.write(answer3);
}
</script>
</head>
<body>
<form>
<input type="text" name="a">
<input type="text" name="b">
<input type="button" onclick="sum(a.value, b.value)">
</form>
</body>
</html>
Comment