check if an unsigned binary number is divisible by 15

Do you know how to check for divisibility by 9 in base 10?

Add all the digits using base 10 arithmetic. If the result has multiple digits, repeat the process. Stop when you have one digit. If the digit is 9, the original number was divisible by 9. This works because the divisor being tested is base-1. For instance 45 is divisible by 9, and the digits sum to 9, only one adder is needed for two digits. 999 is too, two adders are needed for the three digits.

So now do you have a hint of how to test for divisibility by 15 when you have base 16 arithmetic facilities to hand?


The technique is similar to what you would do to check if a number is divisible by 9 in decimal. We need split the number into four bit digits and then add the digits together repeatedly until we have a single digit left.

Lets call the digits X Y Z

c1,r1 = X + Y
c2,r2 = Z + r1 + c1
c3,r3 = r2 + 1

IF X,Y,Z is divisible by 15 then c2,r2 is also divisible by 15. Furthermore c2,r2 is less than 0x1e. So if r=15 then the original number was divisible by 15. We test if r is equal to 15 by adding one and looking at the resulting carry flag.

What is puzzling me is what the nor gate is supposed to be for.