![]() |
| ||
| binary to decimal can someone look at this? in theory it should work but i cant figure it out thanks in advance #include<iostream> |
| ||
| Re: binary to decimal I guess using string is not the good idea. What we use to do was.... some how take the binary in the int or long. then take a loop and extract the element one by one form the last... I guess this is the efficient method.. some how you are wasting too much memory space using string. int dec; |
| ||
| Re: binary to decimal oh sorry i forgot to add i have to use string as binary this is hw for school. pow only works with double. :( |
| ||
| Re: binary to decimal Quote:
if you are such crazy about the string. then you must subtract 48 from the each character of the string as ASCII value of 1 is 49 when you subtract 49-48 = 1 then you can use it as normally |
| ||
| Re: binary to decimal What Quote:
if (test == '1') 1 is different to '1' (character code 49, as Rhohitman said). Also, for powers of 2 you don't have to use pow(). Using the shift operator<< works fine for integers. So pow(2., x)can be replaced with 1<<x |
| ||
| Re: binary to decimal Thanks alot :d |
| All times are GMT -4. The time now is 6:55 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC