MATLAB Answers

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

1 view (last 30 days)
timo
timo on 2 Oct 2016
Commented: dpb on 2 Oct 2016
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 Comment

dpb
dpb on 2 Oct 2016
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

Sign in to comment.

Answers (1)

Peng Liu
Peng Liu on 2 Oct 2016
Not floor(log2(x)) + 1 but ceil(log2(x)) is correct

  1 Comment

Sign in to comment.

Sign in to answer this question.

Tags

No tags entered yet.

Products