maie
Newbie level 5
- Joined
- Sep 30, 2014
- Messages
- 10
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 77
1st you need a word size. Pick an 8, 16, or 32 bit word.
2nd you must define the order of bits by significance, lsb first or last
3rd if you to divide by 5 to get integer solution in binary matching the patterns.
e.g. 0,5,10,15,20,....250,255...
0000 0000
0000 0101
0000 1010
0000 1111 ...
1111 1010
1111 1111
Now you can see the simple state reduction to only 4 patterns on 4 least bits and the rest are (x)
Solution is now trivial pattern match.
I'll work with the number 617283950 = 100100110010110000000101101110.
First split the number into odd and even bits (I'm calling "even" the
bits corresponding to even powers of 2):
100100110010110000000101101110
0 1 0 1 0 0 1 0 0 0 1 1 0 1 0 even
1 0 0 1 0 1 1 0 0 0 0 0 1 1 1 odd
Now in each of these, add and subtract the digits alternately, as in
the standard test for divisibility by 11 in decimal (starting with
addition at the right):
100100110010110000000101101110
+0-1+0-1+0-0+1-0+0-0+1-1+0-1+0 = -2
+1-0+0-1+0-1+1-0+0-0+0-0+1-1+1 = 1
Now double the sum of the odd digits and add it to the sum of the even
digits:
2*1 + -2 = 0
If the result is divisible by 5, as in this case, the number itself is
divisible by 5.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?