So this is an outrage, a simple equation results in a random number that I can make little sense of.
Ok, so I am trying to make an app that converts from Binary to Base Ten. I know one way of doing this is to do this.
Say, 11001 to base ten.
Take the left-most digit: 1
0 * 2 + 1(This 1 is the leftmost binary digit) = 1...
1 * 2 + 1(This 1 is the second leftmost binary digit) = 3...
3 * 2 + 0(etc...) = 6...
6 * 2 + 0 = 12...
12 * 2 + 1 = 25...
So, that correctly converts into 25. Although, when I plug that equation with variables in JavaScript, it turns out random crap.
Watch:
Inputarray is an array of all the characters in the number the user inputted. So, if 11010, then inputarray is 1,1,0,1,0.
Then it loops over each character of the array and plugs each number into the equation as shown.
for (var j=0;j<=uinputlen;j++) {
var nextletter = uinput.charAt(j);
inputarray.push(nextletter);
}
for (var h=0;h<=uinputlen;h++) {
decvalue = decvalue * 2 + inputarray[h];
}
BTW, "decvalue" is preset to 0 at the beginning of my code.
Please comment on any questions on the description or anything else, it is kind of confusing.