http://www.zenoli.net/2007/03/quickly-convert-binary-to-decimal-in-your-head/#comment-293945
that was a neat trick!
Well I have a pretty nice way too to convert a Binary Number to its Decimal Equivalent
Here are the steps:
- Write your number on a paper with the digits spaced by a finger length.
- Starting from the Right Hand Side, write “1” below the first digit.
- Then from RHS to LHS multiply by 2 and write it below.
- Add the numbers that you have written below 1s.
- Its your Decimal Equivalent.
Example:
Convert 10010 Binary no. to its Base 10 equivalent.
1 0 0 1 1
16 8 4 2 1
Now we add 16,2,1. So Decimal Equivalent = 16+2+1 = 19
I think your solution is also tricky and good.
very good trick …when you want to convert large number quick than it is work very fast…
thanks to @va1ts7_100
Well,the trick is quite self explanatory if you already know the method answered by @bradley .
I’ve come up with a theoritical proof one below.
Consider a binary number data to be of the form A101.
Here A can be any binary data
(If A is 1011 , X will be 1011101).
By @bradley method, value of A000 can be calculated(let it be k).
So the value of X(A101) will be - k+(2^2)+(2^0)
Now verifying the trick.
-Consider the trick to be working fine)
-Value of A is k/(2^3)
-Value of A101 is ((k/(2^3)*2+1)*2)*2+1
-Simplifying it we get-k+(2^2)+(2^0)
-This is the correct result.
what does mental number one mean?
- sometimes i feel very hard(in case to be very quick i.e. aptitude ) to calculate decimal number using @bradely method…
*it is good if you want very quick answer than you should go with va1ts7_100
*bcz it does not require to much calculation…
@bradely because you first find all digit value like 16+2+1 than do one more addition…
- but first link provide ans in one scan with very easy to add number.
happy coding…
Thanks va1ts7_100,
it’s a nice way to convert binary to decimal but i can’t understand how to decrease time complexity
to use this method . it is very feasible when we are converting binary to decimal in our mind but it
can’t help in decreasing complexity.
yeap…it use same time complexity as other methods…too $ $only advantage only mind calculation will be easy…
I guess all those who parsed strings to integers manually - should be familiar with this trick. You are doing exactly same when parsing string to decimal - the only difference is that you have base10, therefore you have to do N=N10+digit, instead of N=N2+digit.
@deepakmourya, if you need faster method - you should use divide and conquer with FFT multiplication. Solve your problem for left part of substring, for right part of substring, then multiply result for left part by 10^L and add these two numbers.
Good one…fast method…
wlcm @rcsldav2107…
thanks…