141
rated 0 times
[
148]
[
7]
/ answers: 1 / hits: 41831
/ 7 Years ago, sat, january 21, 2017, 12:00:00
I wrote the following JavaScipt code which converts a binary number into a decimal number:
(function bin_dec(num) {
var x = num;
var result = 0;
for (var i = 0; i < x.length; i++) {
result += eval(x[x.length - i] * 2^i);
}
return result;
})()
I want to be able to run this code from the command-line. The filename is converter.js and I am running the command prompt window in the same directory as the file. I am trying to run this code using 01001100
as the function argument. Here are my attempts:
$ converter.js 01001100
and
$ converter.js -01001100
and
$ converter.js bin_dec(01001100)
But unfortunately, neither of these works. Can somebody please point out my mistake? Thanks in advance.
More From » command-line