ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 07 Apr 2015 05:03:22 -0500Largest 2^n less than x?https://ask.sagemath.org/question/26448/largest-2n-less-than-x/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
CLTue, 07 Apr 2015 00:21:44 -0500https://ask.sagemath.org/question/26448/largest-2n-less-than-x/Answer by tmonteil for <p>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?</p>
<p>Thanks
CL</p>
https://ask.sagemath.org/question/26448/largest-2n-less-than-x/?answer=26449#post-id-26449What 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()`.
Tue, 07 Apr 2015 05:03:22 -0500https://ask.sagemath.org/question/26448/largest-2n-less-than-x/?answer=26449#post-id-26449