位运算实现ushort(16位)转化成long(64位)以及int(32位)

时间:2021-08-18 03:31:50
public static long ushortTolong(ushort pre48, ushort pre32, ushort pre16, ushort pre0)
{
  ulong rt = 0;
  ulong temp = 0;

  temp = pre48;
  rt = temp << 48;
  temp = pre32;
  temp = temp << 32;
  rt = rt | temp;
  temp = pre16;
  temp = temp << 16;
  rt = rt | temp;
  temp = pre0;
  rt = rt | temp;

  return (long)(rt >> 1);
}

public static int ushortToint(ushort pre16, ushort pre0)
{
  uint rt = 0;
  uint temp = 0;

  temp = pre16;
  temp = temp << 16;
  rt = rt | temp;
  temp = pre0;
  rt = rt | temp;

  return (int)(rt >> 1);
}