how to find the nearest smallest power of 2 to an integer?
46 次查看(过去 30 天)
显示 更早的评论
Hello all,
I would like to write a code that finds the nearest smallest power of 2 to integers. For instance, if my integer is 6, its smallest nearest power of 2 is 4, while if the integer is 12, the smallest nearest integer is 8. I would appreciate if somebody can help me please. Thanks.
0 个评论
采纳的回答
Stephen23
2015-5-5
编辑:Stephen23
2015-5-5
>> N = 6;
>> pow2(floor(log2(N)))
ans =
4
>> pow2(floor(log2([6,12])))
ans =
4 8
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!