![]() |
Binary to Decimal conversion
Hello all,
I'm making a script that converts a binary input into a decimal number. I always get a 0 as answer for some reason. Code:
var countMult = 1; |
You are trying to perform the calculation from left to right, but it should be right to left, in other words, start at the end of the string.
Quote:
Try again. |
Is there any point in noting that JavaScript will do this for you?
Code:
<script type="text/javascript">And of course you can go back the other way: Code:
var number = 7181711; |
Quote:
|
Yeah, you are probably right. But in that case the code should be checking for and rejecting any characters other than "1" and "0".
|
fixed
Code:
var countMult = 1;but I still need to reverse the order Code:
var countMult = 1;still working with it |
Code:
var countMult = 1; |
Quote:
|
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"> |
Click on the yellow triangle and don't disable that dialog, at least not while testing.
Then you'll probably want to use Google. |
Can anyone help me do this please??
I've been stuck on this for a few weeks The user enters 0010101 and 010100. These should be converted to decimal (21 and 20, respectively). The Finch will speak that: “The two numbers entered are 21 and 20. Their sum is 41 and when multiplied gives 420. Subtracting the two numbers gives 1”. Please note that the program must *not* use a simple loop which tests for all 127 cases of decimal number in the case of the 7-binary digit number etc. The program must incorporate a proper algorithm for converting the number by parsing (i.e. searching) the string of bits. The program should be tested with binary numbers input from the keyboard as well as from a file. You may decide how the two binary numbers in the file are formatted, e.g., one after the other or separated with a new line. |
Sounds like homework! See forum Rule #1.5.
And please do not hijack someone else's thread. Prefer to start a thread of your own. Hint - try using the search feature of this forum. It is your responsibility to die() if necessary….. - PHP Manual |
Quote:
|
| All times are GMT +1. The time now is 01:36 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.