Ask Your Question
0

Largest 2^n less than x?

asked 2015-04-07 00:21:44 -0600

Other than iterating n and testing against x, is there a particular method in SAGE to find the largest 2^n less than a specified integer?

Thanks CL

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-04-07 05:03:22 -0600

tmonteil gravatar image

updated 2015-04-07 05:07:31 -0600

What about using logarithms and rounding from below using the floor() function ?

Another possibility could be to look at the size of the binary representation of your integer a by using a.binary() or a.bits().

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-04-07 00:21:44 -0600

Seen: 54 times

Last updated: Apr 07 '15