/// <summary> Does an OR operation between two BigInteger instances. /// </summary> /// <remarks>Each BigInteger instance is treated as a two's complement /// representation for the purposes of this operator.</remarks> /// <returns>A BigInteger object.</returns> /// <param name='first'>A BigInteger object.</param> /// <param name='second'>A BigInteger object.</param> public static BigInteger Or(BigInteger first, BigInteger second){ if((first)==null)throw new ArgumentNullException("first"); if((second)==null)throw new ArgumentNullException("second"); BigInteger xa=new BigInteger().Allocate(first.wordCount); Array.Copy(first.reg,xa.reg,xa.reg.Length); BigInteger xb=new BigInteger().Allocate(second.wordCount); Array.Copy(second.reg,xb.reg,xb.reg.Length); xa.negative=first.negative; xa.wordCount=first.wordCount; xb.negative=second.negative; xb.wordCount=second.wordCount; xa.reg=CleanGrow(xa.reg,Math.Max(xa.reg.Length,xb.reg.Length)); xb.reg=CleanGrow(xb.reg,Math.Max(xa.reg.Length,xb.reg.Length)); if(xa.Sign<0){ TwosComplement(xa.reg,0,(int)xa.reg.Length); } if(xb.Sign<0){ TwosComplement(xb.reg,0,(int)xb.reg.Length); } xa.negative|=(xb.Sign<0); OrWords((xa.reg),(xa.reg),(xb.reg),(int)xa.reg.Length); if(xa.Sign<0){ TwosComplement(xa.reg,0,(int)xa.reg.Length); } xa.wordCount=xa.CalcWordCount(); if(xa.wordCount==0)xa.negative=false; return xa; }
/// <summary> </summary> /// <param name='a'>A BigInteger instance.</param> /// <param name='b'>Another BigInteger instance.</param> /// <remarks>Each BigInteger instance is treated as a two's complement /// representation for the purposes of this operator.</remarks> /// <returns>A BigInteger object.</returns> public static BigInteger Xor(BigInteger a, BigInteger b){ if((a)==null)throw new ArgumentNullException("a"); if((b)==null)throw new ArgumentNullException("b"); BigInteger xa=new BigInteger().Allocate(a.wordCount); Array.Copy(a.reg,xa.reg,xa.reg.Length); BigInteger xb=new BigInteger().Allocate(b.wordCount); Array.Copy(b.reg,xb.reg,xb.reg.Length); xa.negative=a.negative; xa.wordCount=a.wordCount; xb.negative=b.negative; xb.wordCount=b.wordCount; xa.reg=CleanGrow(xa.reg,Math.Max(xa.reg.Length,xb.reg.Length)); xb.reg=CleanGrow(xb.reg,Math.Max(xa.reg.Length,xb.reg.Length)); if(xa.Sign<0){ TwosComplement(xa.reg,0,(int)xa.reg.Length); } if(xb.Sign<0){ TwosComplement(xb.reg,0,(int)xb.reg.Length); } xa.negative^=(xb.Sign<0); XorWords((xa.reg),(xa.reg),(xb.reg),(int)xa.reg.Length); if(xa.Sign<0){ TwosComplement(xa.reg,0,(int)xa.reg.Length); } xa.wordCount=xa.CalcWordCount(); if(xa.wordCount==0)xa.negative=false; return xa; }
/// <summary> Returns a BigInteger with every bit flipped. </summary> /// <param name='a'>A BigInteger object.</param> /// <returns>A BigInteger object.</returns> public static BigInteger Not(BigInteger a){ if((a)==null)throw new ArgumentNullException("a"); BigInteger xa=new BigInteger().Allocate(a.wordCount); Array.Copy(a.reg,xa.reg,xa.reg.Length); xa.negative=a.negative; xa.wordCount=a.wordCount; if(xa.Sign<0){ TwosComplement(xa.reg,0,(int)xa.reg.Length); } xa.negative=!(xa.Sign<0); NotWords((xa.reg),(int)xa.reg.Length); if(xa.Sign<0){ TwosComplement(xa.reg,0,(int)xa.reg.Length); } xa.wordCount=xa.CalcWordCount(); if(xa.wordCount==0)xa.negative=false; return xa; }