mustBePowerOf2

Can be used as argements validator. Checks if all numbers of an array are powers of 2.
2 Downloads
Updated 13 Jun 2023

View License

Extends the argument validation functions:
https://www.mathworks.com/help/matlab/matlab_prog/argument-validation-functions.html
mustBePowerOf2(numbers) validates if all the numbers of an array are a power of 2, i.e., check if for every number n in the array log2(n) = k, where k is a non-negative integer. The function throws an error if any number of the array is not a power of 2.
Note: If you want to also check for powers of 2 when k is a negative integer, i.e., fractions where the denominator is a power of 2, you can simply remove the "numbers(iter) < 1 " from the if clause.

Cite As

Christos Milarokostas (2024). mustBePowerOf2 (https://www.mathworks.com/matlabcentral/fileexchange/131029-mustbepowerof2), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2021b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0