2

I am having some difficulty understanding why this recursive algorithm works mathematically for converting decimal to binary.

I understand that the last digit in binary code determines if the decimal number is odd or even, thus we can use the remainder(%) to determine if the last digit is 0(odd) or 1(even). However, my thought process stops there, and I am confused about why the digit in position for 2 to the higher power can be calculated by dividing the decimal by 2 and then check its %2 as shown in the picture.

Can someone help me understand the logic behind the conversion? Thank you very much!

Decimal to Binary

1 Answer 1

2

This is the way to calculate a number in accord to a base, you can do it for every base b>1. for example the same number should be expressed in base b = 3

Start Conversion from base 10 to base 3

26/3 = 8 + 2
8/3 = 2 + 2
(26)_10 = (222)_3 
Proof
2*3^2 + 2*3 + 2*1 = 18+6+2 = 26
Sign up to request clarification or add additional context in comments.

1 Comment

angularindepth.com/posts/1019/… has a great explanation on the math behind the factorization.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.