當前位置: 首頁>>代碼示例>>C#>>正文


C# Number.GetContinuousBitCount方法代碼示例

本文整理匯總了C#中System.Number.GetContinuousBitCount方法的典型用法代碼示例。如果您正苦於以下問題:C# Number.GetContinuousBitCount方法的具體用法?C# Number.GetContinuousBitCount怎麽用?C# Number.GetContinuousBitCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Number的用法示例。


在下文中一共展示了Number.GetContinuousBitCount方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Multiply

		public unsafe ECPoint Multiply (Number scaler)
		{
			ECPoint[] P = SetupMultiplyHelperPoints ();
#if true
			scaler = new Number (scaler, 1);
			int l = scaler.BitCount () - 1;
			int *b = stackalloc int [l >> 2];
			int* e = stackalloc int[l >> 2];
			int d = ComputeSignedWindowDecomposition (scaler, b, e);
			ECPoint Q = P[b[d - 1]];
			for (int i = d - 2; i >= 0; i --) {
				for (int k = 0; k < e[i + 1] - e[i]; k ++)
					Q = Q.Double ();
				if (b[i] > 0)
					Q = Q.Add (P[b[i]]);
				else
					Q = Q.Add (P[-b[i]].Invert ());
			}
			for (int k = 0; k < e[0]; k++)
				Q = Q.Double ();
#else
#if true
			if (P == null) {
				P = _multiplyHelperPoints = new ECPoint[16];
				P[1] = this;
				P[2] = this.Double ();
				P[3] = P[1].Add (P[2]);
				P[5] = P[3].Add (P[2]);
				P[7] = P[5].Add (P[2]);
				P[9] = P[7].Add (P[2]);
				P[11] = P[9].Add (P[2]);
				P[13] = P[11].Add (P[2]);
				P[15] = P[13].Add (P[2]);
			}
			int j = scaler.BitCount () - 1;
			ECPoint Q = _field.GetInfinityPoint (_group);
			while (j >= 0) {
				if (scaler.GetBit (j) == 0) {
					Q = Q.Double ();
					j--;
				} else {
					int n = j - 1;
					uint h = (1 << 3) | (scaler.GetBit (n--) << 2) | (scaler.GetBit (n--) << 1) | scaler.GetBit (n);
					int t = j - 3;
					while ((h & 1) == 0) {
						h >>= 1;
						t++;
					}
					for (int i = 1; i <= j - t + 1; i++)
						Q = Q.Double ();
					Q = Q.Add (P[(int)h]);
					j = t - 1;
				}
			}
#else
			ECPoint inv = Invert ();
			if (P == null) {
				P = _multiplyHelperPoints = new ECPoint[16];
				P[1] = this;
				P[2] = this.Double ();
				P[3] = P[1].Add (P[2]);
				P[5] = P[3].Add (P[2]);
				P[7] = P[5].Add (P[2]);
				P[9] = P[7].Add (P[2]);
				P[11] = P[9].Add (P[2]);
				P[13] = P[11].Add (P[2]);
				P[15] = P[13].Add (P[2]);
			}
			int j = scaler.BitCount () - 1;
			ECPoint Q = _field.GetInfinityPoint (_group);
			while (j >= 0) {
				uint continuous = scaler.GetContinuousBitCount (j);
				if (continuous == 0) {
					Q = Q.Double ();
					j--;
				} else if (continuous <= 4) {
					int n = j - 1;
					uint h = (1 << 3) | (scaler.GetBit (n--) << 2) | (scaler.GetBit (n--) << 1) | scaler.GetBit (n);
					int t = j - 3;
					while ((h & 1) == 0) {
						h >>= 1;
						t++;
					}
					for (int i = 1; i <= j - t + 1; i++)
						Q = Q.Double ();
					Q = Q.Add (P[(int)h]);
					j = t - 1;
				} else {
					Q = Q.Add (this);
					for (uint i = 0; i < continuous; i ++)
						Q = Q.Double ();
					Q = Q.Add (inv);
					j -= (int)continuous;
				}
			}
#endif
#endif
			return Q;
		}
開發者ID:kazuki,項目名稱:opencrypto.net,代碼行數:99,代碼來源:ECPoint.cs


注:本文中的System.Number.GetContinuousBitCount方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。