Welcome, %1$s. Please login or register.

February 21, 2018, 05:09:45 PM
: 1
: Macro to find check divisibility by 16  ( 3341 )
« : May 12, 2007, 12:31:43 AM From Shrinidhi»



Macro to find check divisibility by 16


Write a macro to find whether a number is divisible by 16 or not (without using Math library)

 
Liked It? Share it!

              


« #1 : May 18, 2007, 11:43:30 PM From Prateek»

#define      isDivisibleBy16(x)         !( x & 0xF )


A number is divisible by 2 if its least significant bit is 0.
A number is divisible by 4 if its least 2 significant bits are 0.
A number is divisible by 8 if its least 3 significant bits are 0.
A number is divisible by 16 if its least 4 significant bits are 0.
« #2 : May 19, 2007, 12:08:27 AM From Poonam»

The above macro does not take care of zero condition.
i.e if x is 0 it still returns saying that the number is divisible by zero.
So slightly modifying it.

#define      isDivisibleBy16(x)         (!( x & 0xF ) && x)
« #3 : May 19, 2007, 11:23:26 AM From Ria»

What if the number is negative?
: 1
« previous next »

 

Best RatedList All>>



Latest
Random



SMF 2.0.10 | SMF © 2015, Simple Machines | Contact Webmaster | OnlineFunDb.com © 2009/10 | Legal Disclaimer