Powers of two less than/equal to a given number  TOPIC_SOLVED

Sequences, counting (including probability), logic and truth tables, algorithms, number theory, set theory, etc.

Powers of two less than/equal to a given number

Postby Math Salesman on Mon Oct 25, 2010 11:21 pm

For a given number n, is there a way to determine in general the number of powers of two which are less/equal to n?
I should add that I mean integers.

For example, there are five powers of two less than/equal to 31: 1, 2, 4, 8, 16.
There are two less than/equal to 2: 1, 2

etc.
Math Salesman
 
Posts: 2
Joined: Tue Oct 05, 2010 3:56 pm

Sponsor

Sponsor
 

Re: Powers of two less than/equal to a given number  TOPIC_SOLVED

Postby Math Salesman on Mon Oct 25, 2010 11:26 pm

I just realized that by taking the 'floor' of the base-two logarithm of the number and adding one, I will have the desired result.
Math Salesman
 
Posts: 2
Joined: Tue Oct 05, 2010 3:56 pm


Return to Discrete Math

cron