首页 > 其他 > 详细

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

时间:2015-05-05 19:24:42      阅读:559      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!