Let me give you an example, let's consider the strings: 1000 0101 0111 0000
and the full range of 2-bits strings: 00 01 10 11
i am wondering if there is a function that h开发者_如何学Goas an inverse and that maps the 4 4-bits string to the 2-bits strings.
The number of bijections from a set of n elements to another set of n elements is n!
Consider each destination element consecutively, and pick its matching origin element. For the first, you can pick among n. For the second, you can pick among (n-1). ...
You want a bijection between sets of 4 elements, therefore you have 4! = 24 possible functions.
00 would be mapped to 1000 in six of them (3!), to 0101 in six of them, etc.
I'm not sure this answers your question but that's how I understand it.
For the case of 4 4 bits you have 16 ** 4 or 65536 cases this would map to 8 2 bit cells so it would be a trivial problem. However if you restate your problem to be the bijective mapping of the space of all strings made of 4 bits to 2 bits per byte that is a different problem and yes that has a solution.
A simple solution is look at the mappings to an infinite odd binary string space of each type of pattern. The infinite odd string has a last one a finite distance away from start what you do is you start writing bits as they appear you have one flag if its set and you have done last byte (either the 2 or 4 bit whichever set your using) you write a 1000... if the flag is clear you write 000... since there was a one that is the last "1" in the expansion.
- for the 2 bit set
- 00 sets flag
- 10 does nothing to flag
the rest 01 11 clear the flag
for the 4 bit set
- 0000 sets flag
- 1000 does nothing to flag
- rest all contain at least 1 or more ones and clear the flag
converting 1000 0101 0111 0000 to is a straight copy to 100001010111000010000... notice the tail 100.. since flag set. If you do the reverse for the 2 bit set the flag goes through many state but the 1000.. at end part of flag so in the 2 bit set you get 10 00 01 01 01 11 00 00 no big deal 8 bytes
but on converting 1000 0101 0111 0100 you get 1000010101110000... when looking at 2 bit set you get 10 00 01 01 01 11 10 which is one 2 bit unit shorter for 7 bytes
for this bijection from 4 bit set to 2 bit set there will always be either 2n bytes for the byte of two bytes or 2n-1 bytes where n number of 4 bit bytes.
This method of mapping to the infinite odd files works for bijective transform of any string a member of an infinite set of any number of bytes per byte even if the number of bits that make up a byte vary a a function of n.
精彩评论