Ask Your Question
0

Largest 2^n less than x?

asked 2015-04-07 07:21:44 +0200

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 12:03:22 +0200

tmonteil gravatar image

updated 2015-04-07 12:07:31 +0200

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 07:21:44 +0200

Seen: 120 times

Last updated: Apr 07 '15