# Test if a number is divisible by a power of 2

Submitted by Isoscel on Sat, 08/18/2007 - 22:04.

To test if a number is divisible by 2 is very easy: we just look at its last digit.

If the last digit is even than the number is even.

How do we test if it's divisible by 4? We look at the last 2 digits.

If the number formed by them is divisible by 4 then the whole number is divisible by 4.

For example 473624 is divisible by 4 because 24 is divisible by 4.

For 8? We look at the last 3 digits. For 16 at the last 4.

So for we just consider the number formed by the last n digits.