说一下
int16 x=.....;
byte[] b=new byte[2];
byte[0]=Convert.tobyte((x>>8)&&0x00FF);
byte[1]=Convert.tobyte(x&&0x00FF);
实验一下把,大概就是这样了.
int16 x=.....;
byte[] b=new byte[2];
byte[0]=Convert.tobyte((x>>8)&&0x00FF);
byte[1]=Convert.tobyte(x&&0x00FF);
实验一下把,大概就是这样了.
用指针
这里面我就用char 代替byte了,用16位编译器
char s[2]={高位,低位};
char *p;
int i;/* 16位编译器下,int i占两个字节*/
p=(char *)&i;
*p=s[1];*(p+1)=s[0];i的值就是你所要的值
无符号情况下,只要改变i的定义 unsigned int i;
dim s as int16
dim p as IntPtr
p = System.Runtime.InteropServices.Marshal.AllocHGlobal(2)
System.Runtime.InteropServices.Marshal.WriteByte(p, b(1))
System.Runtime.InteropServices.Marshal.WriteByte(p, 1, b(0))
s = System.Runtime.InteropServices.Marshal.ReadInt16(p)
System.Runtime.InteropServices.Marshal.FreeHGlobal(p)
bt[0] = 255;//高位
bt[1] = 255;//低位
short a = (short)((bt[0]<<8) + bt[1]);
Console.WriteLine(a);