由于需要一个大于64位的数据类型(ulong),因此需要自己写一个数据类型存储大约600位的数据,并能够按位与 按位或
主要用到的技术:
1.操作符重载operator & ,operator |
2.自定义的强制转换 implicit operator
using System;
using System.Collections.Generic;using System.Linq;
using System.Text;
namespace Shujuleixing
{
class Program
{
static void Main(string[] args)
{
LongLongLong x = new ulong[] { long.MaxValue, long.MaxValue, long.MaxValue };
LongLongLong y = new ulong[] { 0, 0, 0 };
LongLongLong huo = x | y;
Console.WriteLine(huo);
LongLongLong yu = x & y;
Console.WriteLine(yu.ToString());
Console.Read();
}
}
public struct LongLongLong
{
public override string ToString()
{
string resultS = "";
foreach (var uulong in ULongList)
{
resultS += Convert.ToString((long)uulong, 2);
}
return resultS;
}
public List<ulong> ULongList;
public static LongLongLong operator |(LongLongLong a, LongLongLong b)
{
var newLongLongLong = new LongLongLong {ULongList = new List<ulong>()};
for (int i = 0; i < a.ULongList.Count; i++)
{
newLongLongLong.ULongList.Add(a.ULongList[i] | b.ULongList[i]);
}
return newLongLongLong;
}
public static LongLongLong operator &(LongLongLong a, LongLongLong b)
{
var newLongLongLong = new LongLongLong {ULongList = new List<ulong>()};
for (int i = 0; i < a.ULongList.Count; i++)
{
newLongLongLong.ULongList.Add(a.ULongList[i] & b.ULongList[i]);
}
return newLongLongLong;
}
public static implicit operator LongLongLong(ulong[] oriLong)
{
var tempL = new LongLongLong { ULongList = oriLong.ToList() };
return tempL;
}
}
}