码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-05-05 19:27:43      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

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);
}

 

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

标签:

原文地址:http://www.cnblogs.com/ttWorld/p/4479744.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!