If I have say $6$ boxes of marbles such that each of the box contains $100$ marbles each of which weigh $1$ gram. Now I get a call from my marble dealer saying that there is a chance that any of the boxes (possibly every one of them) could contain defected marbles which weigh $1$ milligram more than they should.
The question is now how can I figure out how to detect the faulty boxes with one weighing measurement on my scale that I have?
I kinda see the issue if I label the boxes with $1,\dots,6$ and pick correspondingly many marbles from each of the boxes if I knew that only one of these boxes contain defected marbles I could identify it with this strategy as I would end up with $1+ \dots + 6 = 21$ grams and $n$ milligrams where $n$ corresponds to the index of the defected box, but in the case where all of the boxes could be defected the issue is that if I for example end up with $21$ grams and $6$ milligrams it could be that box number $6$ is defected or that boxes number $2$ and $3$ are defected and I'm in trouble.
The way I see this is that I need to get rid of these pesky sums that will ruin the process of detecting the defected boxes by considering indexes for the boxes such that I wont get the possibility that this happens. Is there some trick to index the boxes accordingly?
Method
Label the boxes $0$ through $5$, and take $2^n$ marbles from box $n$.
Weigh the marbles. Since $$ \sum_{j=0}^{5} 2^j = 63$$ marbles have been weighed, the total mass is going to be $63$ grams and $n$ milligrams.
The number can be uniquely written as $$ \sum_{j=0}^{5} 2^{b_j},$$ where each $b_j$ is either $0$ or $1$. In other words, the number has a unique binary representation $$ \bigl( b_5 b_4 b_3 b_2 b_1 b_0 \bigr)_2. $$
If $b_n = 1$, then Box $n$ is defective.
Example
Suppose that the marbles weigh $63$ grams and $47$ milligrams. Observe that $$ 47 = 32^1 + 16^0 + 8^1 + 4^1 + 2^1 + 1^1 = 101111_2.$$ This implies that Box 4 is fine, and that the remaining boxes are defective.