如题 
在VC中 定义成WORD类型 直接用HIBYTE 和LOBYTE就能得到,请问在C#有没有现成的转换函数?

解决方案 »

  1.   

    看看这两个宏的定义,自己写一个就行了#define LOBYTE(w)           ((BYTE)((DWORD_PTR)(w) & 0xff))
    #define HIBYTE(w)           ((BYTE)((DWORD_PTR)(w) >> 8))
      

  2.   

    ushort >> 8、ushort << 8...位运算...
      

  3.   

    使用BitConverter不过做这种事情,C#不太可能比C++方便        static void Main(string[] args)
            {
                short s = 0x51b2;
                byte[] bytes = BitConverter.GetBytes(s);
                Console.WriteLine(bytes[0].ToString("X"));
                Console.WriteLine(bytes[1].ToString("X"));
            }
      

  4.   


    正解,不过稍有补充:ushort >> 8、ushort << 8 >> 8你移到前面去没移回来,哈哈
      

  5.   

    ushort << 8 >> 8也可以是ushort & 0xff
    都是一样的