0

I want to know how can I prove if a binary number is divisible by 3? I've found the answer for a decimal num but I need binary form. (using modular arithmetic a∣b)

Nebula
  • 21

1 Answers1

8

To prove that a certain number is divisible by $3$, the most convincing strategy is to show a number that when multiplied by $3$ yields the target number.

As for a digit-based test for divisibility by $3$:

Count the number of 1 bits in even posititions (that is, ones, fours, sixteens, and so forth). Subtract the number of 1 bits in odd positions (that is, twos, eights, thirty-twos, and so forth). The result of the subtraction is divisible by $3$ if and only if the original number was.

  • thanks for your answer:) I already knew that, do u know if there's any way to prove using modular arithmetic – Nebula Aug 16 '16 at 11:54
  • @3ngineer: I don't understand what it is you're asking, then. – hmakholm left over Monica Aug 16 '16 at 11:55
  • 1
    Indeed, this is the standard test for divisibility by 11 in all number bases, where 11 is interpreted in the base in question. To base $2$, it gives divisibility by $3$, to base $10$ it gives divisibility by $11$, to base $16$ it gives divisibility by $17$. Best of all, to base $1$ it gives divisibility by $2$. – Martin Kochanski Aug 16 '16 at 11:56
  • I've found this answer but i can't get it! http://math.stackexchange.com/questions/979274/determine-whether-or-not-a-binary-number-is-divisible-by-3 – Nebula Aug 16 '16 at 11:56
  • @Martin: It is specific for base two that the instruction can be as simple as "count the ones". In other bases you need to say to "add the digits" at alternating positions. – hmakholm left over Monica Aug 16 '16 at 11:58
  • Yes, that's quite right. Adding and counting are only equivalent for bases $1$ and $2$. – Martin Kochanski Aug 16 '16 at 12:00
  • I mean what if the num was long so i can't count the 1s?! – Nebula Aug 16 '16 at 12:03