1

Given a binary representation of 25 i.e 11001, if I am interested only in the last decimal digit, how do I get it?

  • Just curious: Do you know a method and you're posting as if a puzzle for others? [Or did you just think up this question ?] – coffeemath Jul 03 '15 at 04:43
  • I was trying to solve a question in this link: http://qa.geeksforgeeks.org/331/given-binary-stream-decimal-value-stream-becomes-divisible . So, in this case, we just need to know if last digit is either 5 or 0. – a3.14_Infinity Jul 03 '15 at 04:55

1 Answers1

4

From right to left, the binary place values (mod 10) are $1, 2, 4, 8, 6, 2, 4, 8, 6, \dots$. You can add the reduced (mod 10) place values with $1$s in them, and then mod your answer by ten.

In your example, $11001$, you would add $8 + 6 + 0 + 0 + 1=15\equiv 5 \pmod{10}$.

Arthur
  • 199,419
paw88789
  • 40,402
  • 1
    I was writing a similar answer. It would be good to explicitly note that the binary place values (after the first) cycle with period $4$, so you can add $2$ times the $2^1s, 2^5s, 2^9s \dots $ places where there is a $1$ and so on for the others. It may make the computation easier. +1 – Ross Millikan Jul 03 '15 at 04:59
  • 1
    if you get four 1's in a run (after the first), they can be ignored – JMP Jul 03 '15 at 05:14