Asked Jan 29, 2019

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


Expert Answer

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

Check out a sample Q&A here.

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

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A

Q: I could use help with the following SQL questions (the fields ProductModelName, ProductCategory, Pro...

A: As the table name is not shown in the picture, we are assuming the table name as Product. There are ...


Q: (The Rectangle class) Following the example of the Circle class in Section 8.2,design a class named ...

A: Note: The given program is compiled and executed in "NetbeansIDE" 


Q: Find context-free grammars for the following languages (with n ≥ 0, m ≥ 0)  L = {anbm : n = m − 1}.

A: Solution:A context-free grammar (CFG) is a hard and fast of recursive rewriting guidelines which is ...


Q: make the Matlab code for the given question no 5 and 6

A: Note: This program is compilde and executed in MATLAB/OctaveThe program has the following algorithm:...


Q: This is for python For this assignment, you will write a program to simulate a payroll application. ...

A: Instruction for the given program:Add the given Node class in the python file the given ...


Q: example:"apple-&gt;orange-&gt;banana-&gt;pear"-&gt;NULLreturn "orange"Thanks!

A: ApproachIn the function longest(), we'll declare an integer named highestLength and assign 0 to it.N...


Q: For this program you need to use Eclipse. Carefully read the instructions and write a program that r...

A: The program has the following algorithm: Step 1: Create object for “Scanner” class to read the user ...


Q: You are not required to execute the queries. However, your syntax must by accurate.You must give at ...

A: Hey, since there are multiple sub-part questions posted, we will answer first three questions. If yo...


Q: I need help with the SQL query for the following question: 1.  Get the total number of reviews of mo...

A: The details about the table are given with table name and different entities. Here the table name is...