how to find the nearest smallest power of 2 to an integer?
37 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Stephen23
am 5 Mai 2015
Bearbeitet: Stephen23
am 5 Mai 2015
>> N = 6;
>> pow2(floor(log2(N)))
ans =
4
>> pow2(floor(log2([6,12])))
ans =
4 8
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!