0
binary to decimal
Input :binary number. Output:Its eqivalent decimal. ex: Input:1001. Output:17
32 Answers
+ 1
Sorry.
+ 1
Please post your code, then I can see where you did mistakes.
+ 1
So, i saw you tried it, and because I don't understand everything in your code (no c++ expert)
I'll give you my code.
If you have questions, ask.
https://code.sololearn.com/cmySYgxy5Bkl/?ref=app
0
I want code in java
0
Look, to get the decimal value of a binary number, you use this formula:
i = index
n = number at i
n × Math.pow(2, i);
//You have to sum the value of all calculations
Like:
binary:101
decimal : 1 * Math.pow(2, 0) + 0 * Math.pow (2, 1) + 1 * Math.pow(2, 2)
So, if you want to convert, you have to find a way to
take the number of each index and calculate like above.
0
Then,how to take each number from that given number.And the input is given dynamically.
0
so, at first, i would turn the binary String like
10011 --> 11001
Then you take a for loop starting at 0; Because you turned the String, you can use theString.charAt (i), i would be the variable of the for loop.
0
Can you write the code?
0
Ur logic is wrong.
The actual logic is
if n=1001;y=1;dec=0;
for(n!=0)
{
x=x%10;
dec=dec+2*y;
n=n/10;
y=y*y;
}
0
No, my logic is correct. I've got a working code, but if I would give you a code that you don't understand, it doesn't help.
0
I've got a question, in your posted code there's a variable named x, where do you create it and where you assign a value to it the first time?
0
i explained only logic not the answer .Using that logic we can write the code for my problem.
0
I know how to do that. I gave you ideas how to start off, so write a code. It's not important if it's working, but first, try it yourself. I don't want to throw a code into this thread and you don't understand it.
0
ok.if your code was running succesful .please post the code in comment.
0
Don't you understand me?
0
i tried your logic but not working at all.so, i create a logic its working. This is my intension.
0
Why you think imy logic isn't working?
0
Using with your logic, i write a code and after that i execute that code .finally there is no output .
if, your was succesfully executed .put in your code in comment and i corrected where i gonna do mistakes in that code.
0
I thought you want it to be java?