Main Menu

Deitel Exersices
Downloads
Contact ME


 


Back


Links
CE Main Site
Sharif University
Wikipedia
2Del
PHP
Javascript





    

In the name of GOD


Deitel Exercise : 2.30

Input an integre containing only 0s and 1s (i.e. a "binary" integer) and print its decimal equivalent. Use the modulus and division operators to pick off the "binary" number's digits one at a time from right to left. Much like in the decimal number system, where the right most digit has a positional value of 1, the next digit left has a positional value of 10, then 100, then 1000, and so on, in the binary number system, the right most digit has a positional value of 1, the next digit left has a positional value of 2, then 4, then 8, and so on. Thus the decimal number 234 can be interpreted as 4*1 + 3*10 + 2*100. the decimal equivalent of binary 1101 is 1*1 + 0*2 + 1*4 + 1*8 or 1+0+4+8, or 13. [Note: The reader not familiar with binary numbers might wish to refer to Appendix C.] (In yeki ro sharmande!!! :D )