Probability of 0 bit in ASCII text files

In summary: What is "odds"?I meant the ratio. We can't know what the probability actually was, but we can calculate the ratio of how likely it was to be one thing compared with another. The answer may be written as a fraction, decimal, or percentage.In summary, the probability of drawing a 0 in the second time, given that the first drawing was also a 0, is calculated using Bayes formula as 2/9. This is based on the assumption that the file consists of randomly distributed bits with an equal probability of 0 and 1, as well as a probability of 1/8 for the Most Significant Bit (MSB) being 0.
  • #1
Cylab
54
0
text files consists of 0&1 bits. But in ASCII, Most Significant Bit(MSB) is 0, so we have more 0s than 1s. Assume that we draw bits at random. Question: What is probability of drawing 0 in 2nd time, given 1st drawing was 0?

My Analysis:
From bayes formula, Pr(0) = 1/8*1 + 7/8*1/2 = 9/16, so Pr(1)=7/16 for first drawing of a bit.
Then, it should be like: Pr(0&0) = Pr(0) * Pr(0|0), but I can`t figure out the Pr(0|0)...
Please help!
 
Physics news on Phys.org
  • #2
Are the draws independent? Are we drawing with replacement?
 
  • #3
Even if drawing with replacement, the result of the first draw adds information regarding the file. While it may be ok to assume that non-leading bits are in general equally likely 0 or 1, it will not be true of a given file. Consider a file consisting of a single character. Initially, we know the leading bit is zero and the others equally likely 0 or 1. If first draw returns a 0, what is the probability that it was the leading zero? If it was not, how does that affect the probability of drawing a zero again if first was replaced? What if not replaced?
 
  • #4
(sorry) it is without replacement. (this is part of research) calculation should be based on the description, that is, randomly distributed bits are given, with equal probability of 0 and 1, plus Pr(MSB=0)=1/8(each byte has a MSB=0). So the probability of 0 as whole is 9/16. Question is what is probability of drawing 0 in 2nd time, given 1st time was 0?
 
  • #5
OK. If the file is large then clearly the replacement or otherwise has negligible effect, so the result of the first draw tells you nothing about the second.
For a more modest file, N bytes say, can you calculate the probability that the first bit drawn was a MSB?
 
  • #6
To consult (please correct it if it is wrong, I am doubtful for the second analysis):
The probability of being MSB for first bit drawn;
1) Pr(MSB) = 1/8 (since only 1 MSB in each byte, and characters are stored as byte).
The probability of being 0 for first bit drawn;
2) Pr(0) = 1/8*1 + 7/8*1/2 (due to Bayes formula, if drawn bit is MSB, it is 0 with 100%, if it is NOT MSB, then it is 0 with 50%).
 
  • #7
Cylab said:
To consult (please correct it if it is wrong, I am doubtful for the second analysis):
The probability of being MSB for first bit drawn;
1) Pr(MSB) = 1/8 (since only 1 MSB in each byte, and characters are stored as byte).
The probability of being 0 for first bit drawn;
2) Pr(0) = 1/8*1 + 7/8*1/2 (due to Bayes formula, if drawn bit is MSB, it is 0 with 100%, if it is NOT MSB, then it is 0 with 50%).
No, you're not understanding my question. Given that the first bit drawn was a 0, what is the prob that it was an MSB?
 
  • #8
So there are more questions come, I wish I will have answers at least one of them..Please share your thoughts.
 
  • #9
At first, there are 8 equally likely possibilities, drawing bit 0 (MSB)through to bit 7.
That splits into 15: a double shot at a 0 from bit 0, then 7 equal for a 0 bit from bits 1 to 7, and 7 equal for a 1 bit from bits 1 to 7. Since it turned out to be a 0, you rule out those last 7. That means the prob that it was an MSB is 2/9.
If there are N bytes altogether, there are N MSBs. 2/9 of the time you removed one of these in the first selection, leaving only N-1 MSBs. The other 7/9 times you removed a non-msb.
Can you finish it from there?
 
  • #10
Sorry, I am afraid I can`t! Will you please shed more light.
Reading the description several times, still i find myself unable to follow the logic.
(btw, just in case, with initial requirement, when we draw bits, we don`t know where each byte starts, since these bits(Pr(0)=Pr(1)=1/2, plus Pr(MSB=0)=1/8) are randomly distributed.
 
  • #11
By the way, any idea about the Pr(0)=? of these ASCII bits??
Sorry taking so much of your time.
 
  • #12
With prob 2/9, after getting a 0 bit there are N-1 MSBs and 7N non-MSBs remaining. So prob of drawing a 0 next would be ((N-1)+7N/2)/(8N-1). With prob 7/9 there are N MSBs and 7N-1 non-MSBs remaining, in which case prob of drawing a 0 next would be (N+(7N-1)/2)/(8N-1). Total prob = (2*(N-1)+7N + 7N+7(7N-1)/2)/(9(8N-1)). I leave it to you to simplify that.
 
  • #13
Will you please clarify how prob 2/9 is calculated?
From my understanding is that if there are 15 bits(sequence of bit strings), then
there are 1 or 2 MSB in the strings. So little confused about 2/9.
 
  • #14
In the first draw, you had 2/16 chance of a 0 from an MSB, 7/16 chance of a 0 from a non-MSB, and 7/16 chance of a 1 from a non-MSB. Since you got a 0, you can eliminate the third of these. That leaves a probability 'weight' of 2 for an MSB compared with 7 for a non-MSB, so the odds that it was in fact an MSB are 2/9.
Note, I'm assuming a whole number of bytes in the file.
 
  • #15
haruspex said:
Since you got a 0, you can eliminate the third of these. That leaves a probability 'weight' of 2 for an MSB compared with 7 for a non-MSB, so the odds that it was in fact an MSB are 2/9.

What is the "the third of these"?
What is the "'weight' of 2"?
what is "odds"?
 
  • #16
Cylab said:
What is the "the third of these"?
The "1 from a non-MSB" case.
What is the "'weight' of 2"?
By 'weight' I just mean a share of the remaining probability space.
Initially there are 8 equally likely possibilities corresponding to the 8 positions within a byte.
The MSB always gives a 0, while the other 7 can each give a 0 or a 1. So we can divide the total probability 15 ways, but they are not equal now. A 0 from MSB gets 2 units while each of the other 14 get only 1 unit each. This gave you your 9/16 for a 0 in the first draw.
Once you know you got a 0, that eliminates 7 of the total weight of 16, leaving only a total weight of 9. An MSB in the first draw made 2 of those 9, so the probability that it was an MSB is 2/9.
[/QUOTE]
what is "odds"?[/QUOTE]
That's just another word for probability.
 
  • #17
if this file is text, like English-language text, then some letters are more common than other letters. there are statistics that have results about which letters and characters are more common. i don't know where to find such statistics, but i remember that the letter "e" is the most common. this unequal probability is what is behind the choice of symbols in Morse code. the letter "e" is a single "dit" or "dot" because it is the most common. some similar reason exists with assigning Huffman codes to particular symbols.
 
  • #18
rbj said:
if this file is text, like English-language text..
OP has stated that all bits except MSB are to be assumed equally likely, and independently, 0 or 1.
 
  • #19
Still confused, say, why getting a 0 eliminates 7 of the total weight of 16 etc?.(saying it in simple: we have Pr(MSB=0)=1/8, plus Pr(0)=Pr(1)=1/2, then draw a bit, (as whole) Pr(0)=?, Pr(MSB=0)=?)
Anyway, it seems to follow the rule, where i equals number of 0 drawn sequenced/continual, say i=0,1,2.
1/8 ((i+1)/2^i +(7-i)/2^(i+1))=(i+9)/2^(i+4) .
Agree?
 
  • #20
haruspex said:
A 0 from MSB gets 2 units while each of the other 14 get only 1 unit each.

what do you mean by unit now? is it soooooooo hard to explain in plain words?
 
  • #21
Let's try it using the standard rules of conditional probability.
P[bit was MSB | bit was 0] * P[ bit was 0] = P[bit was MSB & bit was 0] = P[bit was MSB] = 1/8.
P[ bit was 0] = 9/16 (you already proved)
So P[bit was MSB | bit was 0] = (16/9)*(1/8) = 2/9
 
  • #22
haruspex said:
So P[bit was MSB | bit was 0] = (16/9)*(1/8) = 2/9
Thanks for being patient! I understood now. Thanks again.

So you agree that the Prob of drawing a 0 bit in ASCII is Pr(0)=9/16 (given each bit is randomly distributed except MSB)? Then, I still wonder about Pr[0|0]=? (I try to say that Prob of drawing a 2nd 0, given 1st was 0 too). Because I was told 9/16*9/16 comes close but not correct.
 
Last edited:
  • #23
Cylab said:
I still wonder about Pr[0|0]=? (I try to say that Prob of drawing a 2nd 0, given 1st was 0 too). Because I was told 9/16*9/16 comes close but not correct.
The prob of drawing a second 0, given the first was a 0, wouldn't be close to 9/16*9/16. It would be close to 9/16. 9/16*9/16 would be close to the probability for drawing two zeroes, with no prior information. So why isn't 9/16 exactly right? Because the first 0 was not replaced, which might mean there is a smaller number of MSBs available to choose. To figure out how that affects things, you need to calculate the probability that the first was an MSB. We have now done that: 2/9. For the next step see post #12.
 
  • #24
I was told it is 10/32 (drawing two zeroes with prior info), and it follows the rule of 1/8 ((i+1)/2^i +(7-i)/2^(i+1) ). Just can`t figure out.
 
  • #25
Cylab said:
I was told it is 10/32 (drawing two zeroes with prior info), and it follows the rule of 1/8 ((i+1)/2^i +(7-i)/2^(i+1) ). Just can`t figure out.
That says you didn't state the problem correctly. The formula works if the bits are drawn consecutively from the file. Suppose you draw two consecutive bits. prob that one is an MSB is 1/4, so prob of two zeroes is 1/4 * 1/2 + 3/4 * 1/2 * 1/2 = 5/16.
You already know prob that first was a 0 was 9/16. Using the joint probability rule, you can easily calculate the prob that second is a zero given the first was. Do you see how?
 
  • #26
haruspex said:
That says you didn't state the problem correctly. The formula works if the bits are drawn consecutively from the file. Suppose you draw two consecutive bits. prob that one is an MSB is 1/4, so prob of two zeroes is 1/4 * 1/2 + 3/4 * 1/2 * 1/2 = 5/16.
You already know prob that first was a 0 was 9/16. Using the joint probability rule, you can easily calculate the prob that second is a zero given the first was. Do you see how?

Sorry for the statement, the bits are drawn consecutively (successive bits). So the problem is about Prob of drawing a 0 bit, 2 successive 0 bits(00) and 3 successive 0 bits(000) respectively. I just couldn`t make correct calculation, sorry.
PLEASE!
 
  • #27
OK. First we need the probability that N successive bits are all zero. For now, assume N < 9. What is the probability that the N include an MSB? N/8, right?
If they do include an MSB, what is the prob they are all 0? There must be exactly one MSB, so it's 2-(N-1) ok? And if they don't, it's 2-N. So in total 2-N(1+N/8).
Now suppose we know the first N-1 were all zero and we want the prob that the Nth is too. By the conditional/joint probability rule, we can just take the ratio of two of these probs:
2-N(1+N/8)/(2-(N-1)(1+(N-1)/8)) = (8+N)/(2(7+N))
Do you also need to investigate N > 8?
 
  • #28
Thanks, let me understand your explanation first. I think it takes sometime!
 
  • #29
haruspex said:
OK. First we need the probability that N successive bits are all zero. For now, assume N < 9. What is the probability that the N include an MSB? N/8, right?

1st: the Prob of having 3 successive 0 bits(000) is ;
3/8*1/2 + 5/8*1/2*1/2 = 11/32.

Since you computed of having 2 successive 0 bits is 10/32.
So my calculation of (000) seems wrong?

2nd : if it follows to the rule of (2^-N)(1+N/8),
Then 5 successive 0 bits(00000) would be:
2^5(1+5/8)= 13/512

So my calculation of (000) seems wrong.
Will you please share your thoughts?
 
Last edited:
  • #30
Cylab said:
1st: the Prob of having 3 successive 0 bits(000) is ;
3/8*1/2 + 5/8*1/2*1/2 = 11/32.
How do you get that? Should be 3/8*1/2*1/2 + 5/8*1/2*1/2*1/2 = 11/64
2nd : if it follows to the rule of (2^-N)(1+N/8),
Then 5 successive 0 bits(00000) would be:
2^5(1+5/8)= 13/512
No, 13/256
 
  • #31
haruspex said:
How do you get that? Should be 3/8*1/2*1/2 + 5/8*1/2*1/2*1/2 = 11/64

No, 13/256

You are right. Thanks.
Please let me confirm about the "1/2".
1st.
Analysis: The number of "1/2 " at the right part (of +) is 2^-(N-1), and left is 2^-N.
right? but Where the " number of 1/2 " comes from? Is that because of the N that is number of successive zero bits taken from ASCII?
2nd.
If N>8, then we should assume it is impossible. In other words, the answer should be 0. Am I correct?
 
Last edited:
  • #32
Cylab said:
Where the " number of 1/2 " comes from? Is that because of the N that is number of successive zero bits taken from ASCII?
Yes. If N ≤ 8, one of the N might be a leading bit, but only one.
With probability N/8, there is a leading bit. That bit will be 0. The other N-1 may be 0 or 1, equally likely. So prob that all N are 0 is 2-(N-1).
With prob 1-N/8, there is no leading bit. All N may be 0 or 1, equally likely. So prob that all N are 0 is 2-N.
Adding up: (N/8)*2-(N-1) + (1-N/8)*2-N = 2-N(1+N/8).
If N>8, then we should assume it is impossible. In other words, the answer should be 0.
Not at all. You are now guaranteed one leading 0, and the question becomes whether there's 1 or 2. In general, if we write N = 8A+B, B < 8, what do you think the formula would be?
 
  • #33
haruspex said:
Adding up: (N/8)*2-(N-1) + (1-N/8)*2-N = 2-N(1+N/8).

Thanks. the explanations are really helpful.
So in other words,
「We can assume that there are seven bits (or N<8) and that there is at most one MSB bit (which means either one MSB or zero MSB) in it. Thus we can compute the probability of having zero MSB, plus the probability of having one MSB. right ?」


haruspex said:
Not at all. You are now guaranteed one leading 0, and the question becomes whether there's 1 or 2. In general, if we write N = 8A+B, B < 8, what do you think the formula would be?

Analysis:
1st. as the same token, If we let N be 15bits , then the it must contain at least one MSB or at most two MSBs. We add the probability of having one MSB and having two MSBs in it.
2nd. further, when N is 37 bits, then it must contain at least four or at most five MSBs. And so on ...
So what it turns out to be? Just replacing N with 8A+B seems not sufficient for the computations, unless I understand what 'A', 'B' stand for.
Will you furnish some explanations further please?
 
  • #34
Cylab said:
1st. as the same token, If we let N be 15bits , then the it must contain at least one MSB or at most two MSBs. We add the probability of having one MSB and having two MSBs in it.
How about you complete that and post the formula you get?
2nd. further, when N is 37 bits, then it must contain at least four or at most five MSBs. And so on ...
So what it turns out to be? Just replacing N with 8A+B seems not sufficient for the computations, unless I understand what 'A', 'B' stand for.
A and B are integers, 0 ≤ B < 8, N=8A+B. That completely defines A and B. A = integer part of N/8; B = N modulo 8.
 
  • #35
haruspex said:
How about you complete that and post the formula you get?

A and B are integers, 0 ≤ B < 8, N=8A+B. That completely defines A and B. A = integer part of N/8; B = N modulo 8.

OK! But the analysis concentrates on MSB only (say, N=7); so the formula maybe like;
P(MSB)=P(MSB |H0)P(H0) + P(MSB |H1)P(H1)
(Let Hi be the event that there are i MSB bits in N, for i = 0, 1, 2, 3….. )
where P(MSB |H0) stands for conditional probability of MSB bit in N given it is H0 which equals 0 (no MSB) and P(MSB |H1) stands for conditional probability of MSB bit in the N given it is H1 which equals 1/7 (one MSB);

But it is little different from the point of N=8A+B. right?
I could not figure out the computation.
 
<h2>1. What is the probability of a 0 bit occurring in an ASCII text file?</h2><p>The probability of a 0 bit occurring in an ASCII text file depends on the specific file and its contents. However, in general, ASCII text files are made up of 8-bit characters, so the probability of a 0 bit occurring is approximately 1/8 or 12.5%.</p><h2>2. How does the probability of a 0 bit change in different types of ASCII text files?</h2><p>The probability of a 0 bit occurring in an ASCII text file can vary depending on the type of file and its contents. For example, a file with mostly lowercase letters will have a higher probability of 0 bits compared to a file with mostly numbers or special characters.</p><h2>3. Is the probability of a 0 bit in ASCII text files affected by file size?</h2><p>The probability of a 0 bit in ASCII text files is not directly affected by file size. However, larger files may contain a higher number of 0 bits simply due to the increased number of characters in the file.</p><h2>4. Can the probability of a 0 bit be calculated for a specific ASCII text file?</h2><p>Yes, the probability of a 0 bit can be calculated for a specific ASCII text file by counting the total number of bits in the file and then determining the number of 0 bits. The probability can then be calculated as the number of 0 bits divided by the total number of bits.</p><h2>5. How does the probability of a 0 bit in ASCII text files relate to data compression?</h2><p>The probability of a 0 bit in ASCII text files is important in data compression because it can help determine the most efficient way to compress the file. If a file has a high probability of 0 bits, it may be more easily compressed using certain algorithms compared to a file with a lower probability of 0 bits.</p>

1. What is the probability of a 0 bit occurring in an ASCII text file?

The probability of a 0 bit occurring in an ASCII text file depends on the specific file and its contents. However, in general, ASCII text files are made up of 8-bit characters, so the probability of a 0 bit occurring is approximately 1/8 or 12.5%.

2. How does the probability of a 0 bit change in different types of ASCII text files?

The probability of a 0 bit occurring in an ASCII text file can vary depending on the type of file and its contents. For example, a file with mostly lowercase letters will have a higher probability of 0 bits compared to a file with mostly numbers or special characters.

3. Is the probability of a 0 bit in ASCII text files affected by file size?

The probability of a 0 bit in ASCII text files is not directly affected by file size. However, larger files may contain a higher number of 0 bits simply due to the increased number of characters in the file.

4. Can the probability of a 0 bit be calculated for a specific ASCII text file?

Yes, the probability of a 0 bit can be calculated for a specific ASCII text file by counting the total number of bits in the file and then determining the number of 0 bits. The probability can then be calculated as the number of 0 bits divided by the total number of bits.

5. How does the probability of a 0 bit in ASCII text files relate to data compression?

The probability of a 0 bit in ASCII text files is important in data compression because it can help determine the most efficient way to compress the file. If a file has a high probability of 0 bits, it may be more easily compressed using certain algorithms compared to a file with a lower probability of 0 bits.

Similar threads

  • Set Theory, Logic, Probability, Statistics
Replies
7
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
1
Views
773
  • Precalculus Mathematics Homework Help
Replies
6
Views
794
  • Set Theory, Logic, Probability, Statistics
Replies
7
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
6
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
6
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
15
Views
1K
  • Precalculus Mathematics Homework Help
Replies
12
Views
2K
  • Atomic and Condensed Matter
Replies
3
Views
733
  • Set Theory, Logic, Probability, Statistics
Replies
17
Views
2K
Back
Top