将2字节转换为1字节??? [英] Converting 2 byte to 1 byte???

查看:657
本文介绍了将2字节转换为1字节???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何数学转换方法,以便我可以将2个字节的数据(例如HEX中的FF&DA)转换为一个字节(说HEX中的AD),然后再次从该单个字节中恢复原来的2个字节? :doh::doh:

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:

推荐答案

简短答案:否.

更长(但仍然很简单)的答案:在两个字节中,您可以表示65536(= 256 * 256)个不同的值.在一个字节中,您可以表示256个不同的值.因此,您可以选择两个字节的值中的256个来回转换,但是一旦使用了更多的内容,就无法唯一地转换回去.

投票答案,并在适当的情况下标记为接受.

彼得
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


您要的是MSB(最高有效字节),LSB(最低有效字节)

某些协议(Xmodem,Kermit)将一个字节发送为两个字节(有时)

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


不会.
将整个2字节值集转换为整个1字节值集的过程不是模棱两可的,因此不能反转(请参见 bijection [^ ],位于 Wikipedia ).
:)
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).
:)


这篇关于将2字节转换为1字节???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆