Power of 2

Write a method that takes in a number and returns true if it is a power of 2. Otherwise, return false.

You may want to use the % modulo operation. “5 % 2” returns the remainder when dividing 5 by 2; therefore,  “5 % 2 == 1”. In the case of “6 % 2”, since 2 evenly divides 6 with no remainder, “6 % 2 == 0”.

My answer:

Screen Shot 2016-08-12 at 3.36.35 PM

Provided solution:

Screen Shot 2016-08-12 at 3.38.33 PM

Second time doing this:

screen-shot-2016-09-30-at-4-21-22-pm

Advertisements
Power of 2

Leave a Reply

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s