# How do I check if a binary number is a multiple of 16 by using bit shifting?

Question
53 views

How do I check if a binary number is a multiple of 16 by using bit shifting?

check_circle

Step 1

Approach: Result = (((n >>4) << 4) == n). First we shift the 4 bit right then we shift the 4 bit left and then compare the number with the given number. If the resultant number is equal to the original number then it is the divisible by 16 .

Step 2

Example: If n = 16 is given so binary of the 16 is 10000, now after we shift the 4 bit right we get 00001 so again we shift the 4 bit left, then we have 10000. Compare it with the given number first 16==16 in binary so it is true and thus the number is divisible by 16.

Step 3

Example: If n = 32 is given so binary of the 32 is 100000, now after we shift the 4 bit right we get 00010 so again we shift the 4 bit left, then we have 100000. Compare it with the given number first 32==32 in binary so it is true and thus the number is divisible by 16.

...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

### Computer Science 