is there a built in function to get minimum nr of bits for an integer ?

I have found the formula for minimum nr of bits for a integer
bspec = floor(log2(16)) + 1
Is there a built in function for this in MATLAB ?

1 件のコメント

dpb
dpb 2016 年 10 月 2 日
When you write one, there will be... :)
But, what do you need a function for a constant; unless you intended the argument '16' to be a variable based on the length of a word???
If the object is to find out the size of an integer, see
doc class
doc isa

サインインしてコメントする。

回答 (1 件)

Peng Liu
Peng Liu 2016 年 10 月 2 日

0 投票

Not floor(log2(x)) + 1 but ceil(log2(x)) is correct

1 件のコメント

dpb
dpb 2016 年 10 月 2 日
Good catch; but I still wonder what OP actually wants... :)

サインインしてコメントする。

カテゴリ

製品

タグ

タグが未入力です。

質問済み:

2016 年 10 月 2 日

コメント済み:

dpb
2016 年 10 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by