How many bytes contain exactly two 1's?

  • MHB
  • Thread starter find_the_fun
  • Start date
  • Tags
    bytes
In summary, the conversation discusses the number of bytes that contain exactly two 1's. The answer key gives \binom{8}{2}, which is found by considering the number of ways to choose two bit positions from a total of 8. However, this can also be seen as dividing by 2 to account for order not mattering. The original approach of considering the remaining 6 bits as zeroes is also correct.
  • #1
find_the_fun
148
0
How many bytes contain exactly two 1's?

The answer key give \(\displaystyle \binom{8}{2}\) and I don't get why. Even if two bytes have been taken there are still \(\displaystyle 2^6\) ways to arrange the other bytes, which is much larger than 28.
 
Physics news on Phys.org
  • #2
You could look at it this way:

There are 8 bit positions you could choose for the first 1 and that leaves 7 for the second bit position. But, order does not matter, so you want to divide by 2 so that you do not count each possible permutation twice. For example, suppose you chose the third bit the first time and the fifth bit the second time. This is equivalent to choosing the fifth bit the first time and the third bit the second time. So, we find:

\(\displaystyle N=\frac{8\cdot7}{2}=28\)
 
  • #3
MarkFL said:
You could look at it this way:

There are 8 bit positions you could choose for the first 1 and that leaves 7 for the second bit position. But, order does not matter, so you want to divide by 2 so that you do not count each possible permutation twice. For example, suppose you chose the third bit the first time and the fifth bit the second time. This is equivalent to choosing the fifth bit the first time and the third bit the second time. So, we find:

\(\displaystyle N=\frac{8\cdot7}{2}=28\)

What I don't see is why the way I was looking at it was wrong.
 
  • #4
If you have already chosen the two bits that are 1, then the remaining 6 bits must be zeroes, and there is only 1 way this can be.
 
  • #5
MarkFL said:
If you have already chosen the two bits that are 1, then the remaining 6 bits must be zeroes, and there is only 1 way this can be.

That's what I was waiting for someone to say! I don't know what's wrong with me I need more sleep.
 

1. How do you calculate the number of bytes containing exactly two 1's?

To calculate the number of bytes containing exactly two 1's, you can use the formula 2^(n-1) * (n-1), where n is the number of bits in the byte. For example, a 4-bit byte would have 2^(4-1) * (4-1) = 8 possible combinations with exactly two 1's.

2. What is the maximum number of bytes that can contain exactly two 1's?

The maximum number of bytes that can contain exactly two 1's is determined by the number of bits in the byte. For an 8-bit byte, the maximum number is 255, while for a 16-bit byte, the maximum is 65,535.

3. Can a byte contain more than two 1's?

Yes, a byte can contain more than two 1's. The number of possible combinations with more than two 1's increases as the number of bits in the byte increases.

4. How does the number of 1's in a byte affect its size?

The number of 1's in a byte does not directly affect its size. The size of a byte is determined by the number of bits it contains, with a standard byte being 8 bits. However, the number of 1's can affect the overall size of a larger data structure, such as a file, which may contain multiple bytes.

5. What is the significance of counting bytes with exactly two 1's?

Counting bytes with exactly two 1's can be useful in certain applications, such as error detection or data compression. It can also help in understanding the overall distribution of 1's and 0's in a binary system. However, it is not a commonly used metric in most computing applications.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
3
Views
997
Replies
1
Views
590
  • Programming and Computer Science
Replies
9
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
5
Views
1K
  • Programming and Computer Science
Replies
3
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
627
Back
Top