General Discussions

Check if all Bits Set

To check if all the bits are set for a given number, AND the given number n with n+1. If all the bits are set, then the result will be 0.

Examples:

n = 4          100
n+1 = 5      101
———————– AND
result         100

n = 7          0111
n+1 = 8      1000
———————– AND
result         0000

Advertisements

Let me Know What you Think!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s