如何将LSB转换为MSB以及如何将MSB转换为LSB

如何将LSB转换为MSB以及如何将MSB转换为LSB

问题描述:

帮助请......

short int wavein [644];

wavein [0] = sizeof(wavein);
wavein [1] = 0;

在这里,我正在通过套接字发送wavein数据....我正在使用鲨鱼监视它的状态为84 02 0000.在这里,我需要将其发送为02 84 00 00.谁能告诉我如何进行移位操作以发送像这种格式的数据02 84(六进制值644为0284)..在这里,我需要将LSB更改为MSB,将MSB更改为LSB .....请回复. .感谢您的宝贵意见.

Help Pls....

short int wavein[644];

wavein[0]=sizeof(wavein);
wavein[1]=0;

here i am sending wavein data through socket....I am monitoring using wire shark it is going as 84 02 00 00. here i need to sent as 02 84 00 00 . can any one pls tell me how to do shift operation to send data like this format 02 84 (hexa value of 644 is 0284)..here i need to change LSB to MSB and MSB to LSB .....Pls reply...Thanks for ur valuable comment

htons()是您的朋友.并且便携.它从主机的字节顺序转换为格式为short的网络.

如果需要对32位数据执行相同的操作,则有一个htonl.
htons() is your friend. And portable. It converts from the byte order of the host to a a network formatted short.

There''s an htonl if you ever need to do the same thing with 32 bit data.


通过网络传输数据时,应使用主机到网络功能来执行以下操作:确保您始终以系统的方式发送它.在这里 htons() [ ^ ]和此处 ntohs() [ ^ ]重新找回.
When transmitting data over a network, you should use host-to-net functions to make sure you always send it in a systematic way. Look here htons()[^] and here ntohs()[^] to get it back again.