Counting active binary combinations

Hi,
I am trying to solve a problem to no avail. I have a 64-bit binary string. The problem requires that only 8-to-16 of these bits can be active (equal to 1). How would I determine the number of such combinations for which this can be true?
I thought I had the solution when I formed the equation:
x=((2^n)-1)*(m-n+1);
Where:
x = number of unique combinations (?),
m = bit string length (64 here), and
n = length of active range (16-8 = 8 here).
However, this only gave the answer for when the active bits were within an 8-bit range of each other in the bit string length. The actual answer must consider situations where those 8-to-16 bits can be anywhere in the 64-bit string.
Please help!

 採用された回答

James Tursa
James Tursa 2017 年 9 月 19 日

1 投票

You are choosing a combination of 64 bits taken 8-to-16 at a time. So add them up:
s = 0;
n = 64;
for k=8:16
s = s + nchoosek(n,k);
end
A big number
7.1325e+14

2 件のコメント

Walter Roberson
Walter Roberson 2017 年 9 月 19 日
Right. Or is the question about verifying that a particular given combination only has 8 to 16 bits set??
Enrico8
Enrico8 2017 年 9 月 21 日
編集済み: Enrico8 2017 年 9 月 21 日
Thank you! That makes perfect sense. I just could not get my head around it. Thanks very much.

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

その他の回答 (0 件)

カテゴリ

製品

質問済み:

2017 年 9 月 19 日

編集済み:

2017 年 9 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by