Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there any mathematical transformation method so that I can convert 2 byte data(say FF & DA in HEX) to a single byte(Say AD In HEX) and again recover the original 2 byte from the single byte?? :doh: :doh:
Posted

Short answer: NO.

Longer (but still simple) answer: In two bytes, you can express 65536 (= 256 * 256) different values. In one byte, you can express 256 different values. So you could pick 256 of your two-byte values to convert back and forth, but once you use any more, you can't convert back uniquely.

Vote for answers, and mark accepted if appropriate.

Peter
 
Share this answer
 
Are You asking for MSB(Most significant Byte),LSB(Least significant Byte)

Some Protocols(Xmodem, Kermit) sends a byte as two bytes(some times)

For example : orginal byte : 256 
    it will sends 2 bytes 
            256/255 = 1
            256%255 = 255
 
Share this answer
 
Nope.
Any transformation of the whole set of 2 bytes values into the whole set of 1 byte values is not injective so cannot be inverted (see bijection[^] at Wikipedia).
:)
 
Share this answer
 
v2
Comments
Dalek Dave 3-Nov-10 6:14am    
True!
No. You're actually adding overhead since you'll need some other data to "expand" the compressed byte back to its original value. You're not gaining anything by doing the "compression".

Compression techniques work over a larger block of bytes. The smaller the dataset, the less efficient compression becomes.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900