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)
Asked
Active
Viewed 4,948 times
0
-
The notation $a|b$ has nothing to do with modular arithmetic. What do you mean? – Git Gud Aug 16 '16 at 11:48
-
1@GitGud I think I agree with your point, but it is a little unfair to say it has nothing to do with it. For example I have seen as a definition $a|b \iff a \equiv 0 \mod b$ – Carser Aug 16 '16 at 11:54
-
1Possible duplicate of Determine whether or not a binary number is divisible by $3$ – barak manos Aug 16 '16 at 12:03
-
@barakmanos Can u explain the equation please?! – Nebula Aug 16 '16 at 12:07
-
@3ngineer: What equation? – barak manos Aug 16 '16 at 12:23
-
@barakmanos the one in this page http://math.stackexchange.com/questions/979274/determine-whether-or-not-a-binary-number-is-divisible-by-3 – Nebula Aug 16 '16 at 17:47
-
@3ngineer: You can write a comment under that answer, and ask the author directly. – barak manos Aug 17 '16 at 05:06
-
I already know that I should ask the author, but I can't cause of my reputation :| @barakmanos – Nebula Aug 17 '16 at 09:41
1 Answers
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.
hmakholm left over Monica
- 291,611
-
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
-
1Indeed, this is the standard test for divisibility by
11in all number bases, where11is 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
-