识别套接字消息(扩展名)在十进制和十六进制之间切换

时间:2014-05-02 09:53:35

标签: c# sockets hex decimal

这是another question.

扩展中的问题

我想知道:

  1. 如果代码显示为workSocket.dataBuffer[3],则它等于workSocket.dataBuffer[0x33],对吗?但是从enter link description here,33转换为51,因此workSocket.dataBuffer[0x33]对应workSocket.dataBuffer[51]

  2. 下面的代码执行了很多| =比较和移位字节<&lt ;.这些比较的用途是什么?

  3. 如果我想将workSocket.m_Ch1设为40,将workSocket.m_Ch2设为40,那么输入workSocket.dataBuffer应该是什么?

  4. 代码如下:

    workSocket.UniqueNum = (uint) (((workSocket.dataBuffer[0xb9] << 8) | workSocket.dataBuffer[0xb8]) | -2147483648);
    workSocket.Information = 0;
    workSocket.Information |= (uint) ((workSocket.dataBuffer[0x1b] & 12) << 8);
    workSocket.Information |= (uint) ((workSocket.dataBuffer[40] & 12) << 6);
    workSocket.Information |= (uint) ((workSocket.dataBuffer[0x76] & 12) << 4);
    workSocket.Information |= (uint) ((workSocket.dataBuffer[0x1b] & 3) << 4);
    workSocket.Information |= (uint) ((workSocket.dataBuffer[40] & 3) << 2);
    workSocket.Information |= (uint) (workSocket.dataBuffer[0x76] & 3);
    workSocket.Information |= 0xc0000000;
    
    num2 = (workSocket.dataBuffer[0x10] << 8) + workSocket.dataBuffer[15];
    if (num2 > 10)
          {
           workSocket.m_Ch1 = ((float) (num2 + 190)) / 228f;
          }
    else
          {
           workSocket.m_Ch1 = 0f;
          }
    num2 = (workSocket.dataBuffer[0x1f] << 8) + workSocket.dataBuffer[30];
    if (num2 > 10)
          {
          workSocket.m_Ch2 = ((float) (num2 + 0x99)) / 236f;
          }
    else
          {
          workSocket.m_Ch2 = 0f;
          }
    

0 个答案:

没有答案