Question

Asked Jan 29, 2019

53 views

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

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.

Tagged in

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 Node.py.Add the given ...

Q: example:"apple->orange->banana->pear"->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...