拆分Int64/long 到HighPart/LowPart类型

该博客为转载内容,转载自https://www.cnblogs.com/skyfei/archive/2005/07/05/186756.html ,涉及C#相关知识。
今天研究C#调用API,需要把long类型拆分成LowPart和HighPart两部分,所以写了一个方法,来转换这两种类型。

 1None.gifusing System;
 2None.gif
 3None.gifnamespace Skyfei
 4ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 5InBlock.gif    public struct LargeInteger
 6ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 7InBlock.gif        Int32 _LowPart;
 8InBlock.gif        Int32 _HighPart;
 9InBlock.gif        public Int32 LowPart
10ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
11InBlock.gif            get
12ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
13InBlock.gif                return _LowPart;
14ExpandedSubBlockEnd.gif            }

15InBlock.gif            set 
16ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
17InBlock.gif                _LowPart = value;
18ExpandedSubBlockEnd.gif            }

19ExpandedSubBlockEnd.gif        }

20InBlock.gif    
21InBlock.gif        public Int32 HighPart
22ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
23InBlock.gif            get
24ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
25InBlock.gif                return _HighPart;
26ExpandedSubBlockEnd.gif            }

27InBlock.gif            set 
28ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
29InBlock.gif                _HighPart = value;
30ExpandedSubBlockEnd.gif            }

31ExpandedSubBlockEnd.gif        }

32ExpandedSubBlockEnd.gif    }

33ExpandedSubBlockStart.gifContractedSubBlock.gif    /**//// <summary>
34InBlock.gif    /// LargeInteger 的摘要说明。
35ExpandedSubBlockEnd.gif    /// </summary>

36InBlock.gif    public class LInteger
37ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
38InBlock.gif        
39InBlock.gif        public LInteger()
40ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
41InBlock.gif            //
42InBlock.gif            // TODO: 在此处添加构造函数逻辑
43InBlock.gif            //
44ExpandedSubBlockEnd.gif        }

45InBlock.gif
46InBlock.gif        public static long GetLongValue(LargeInteger largeInteger)
47ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{            
48InBlock.gif            return (long)(((ulong)largeInteger.HighPart << 32+ (uint)largeInteger.LowPart);
49ExpandedSubBlockEnd.gif        }

50InBlock.gif
51InBlock.gif        public static LargeInteger GetLargeIntegerValue(long longNumber)
52ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{        
53InBlock.gif            LargeInteger t = new LargeInteger();
54InBlock.gif            t.LowPart = (Int32) longNumber;
55InBlock.gif            t.HighPart = (Int32) (longNumber >> 32);
56InBlock.gif            return t;
57ExpandedSubBlockEnd.gif        }

58ExpandedSubBlockEnd.gif    }

59ExpandedBlockEnd.gif}

60None.gif

转载于:https://www.cnblogs.com/skyfei/archive/2005/07/05/186756.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值