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


C# BigInteger.RightShift操作符代碼示例

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


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

示例1:

var number = BigInteger.Parse("-9047321678449816249999312055");
Console.WriteLine("Shifting {0} right by:", number);
for (int ctr = 0; ctr <= 16; ctr++) {
   BigInteger newNumber = number >> ctr;
   Console.WriteLine(" {0,2} bits: {1,35} {2,30}", ctr, newNumber, newNumber.ToString("X"));
}
開發者ID:.NET開發者,項目名稱:System.Numerics,代碼行數:6,代碼來源:BigInteger.RightShift

輸出:

Shifting -9047321678449816249999312055 right by:
0 bits:       -9047321678449816249999312055       E2C43B1D0D6F07D2CC1FBB49
1 bits:       -4523660839224908124999656028       F1621D8E86B783E9660FDDA4
2 bits:       -2261830419612454062499828014        8B10EC7435BC1F4B307EED2
3 bits:       -1130915209806227031249914007        C588763A1ADE0FA5983F769
4 bits:        -565457604903113515624957004        E2C43B1D0D6F07D2CC1FBB4
5 bits:        -282728802451556757812478502        F1621D8E86B783E9660FDDA
6 bits:        -141364401225778378906239251         8B10EC7435BC1F4B307EED
7 bits:         -70682200612889189453119626         C588763A1ADE0FA5983F76
8 bits:         -35341100306444594726559813         E2C43B1D0D6F07D2CC1FBB
9 bits:         -17670550153222297363279907         F1621D8E86B783E9660FDD
10 bits:          -8835275076611148681639954          8B10EC7435BC1F4B307EE
11 bits:          -4417637538305574340819977          C588763A1ADE0FA5983F7
12 bits:          -2208818769152787170409989          E2C43B1D0D6F07D2CC1FB
13 bits:          -1104409384576393585204995          F1621D8E86B783E9660FD
14 bits:           -552204692288196792602498           8B10EC7435BC1F4B307E
15 bits:           -276102346144098396301249           C588763A1ADE0FA5983F
16 bits:           -138051173072049198150625           E2C43B1D0D6F07D2CC1F

示例2: if

var number = BigInteger.Parse("-9047321678449816249999312055");
Console.WriteLine("Shifting {0} right by:", number);
for (int ctr = 0; ctr <= 16; ctr++) {
   BigInteger newNumber = BigInteger.Divide(number, BigInteger.Pow(2, ctr));
   if (newNumber * ctr < 0)
      newNumber--;
   
   Console.WriteLine(" {0,2} bits: {1,35} {2,30}", 
                     ctr, newNumber, newNumber.ToString("X"));
}
開發者ID:.NET開發者,項目名稱:System.Numerics,代碼行數:10,代碼來源:BigInteger.RightShift

輸出:

0 bits:       -9047321678449816249999312055       E2C43B1D0D6F07D2CC1FBB49
1 bits:       -4523660839224908124999656028       F1621D8E86B783E9660FDDA4
2 bits:       -2261830419612454062499828014        8B10EC7435BC1F4B307EED2
3 bits:       -1130915209806227031249914007        C588763A1ADE0FA5983F769
4 bits:        -565457604903113515624957004        E2C43B1D0D6F07D2CC1FBB4
5 bits:        -282728802451556757812478502        F1621D8E86B783E9660FDDA
6 bits:        -141364401225778378906239251         8B10EC7435BC1F4B307EED
7 bits:         -70682200612889189453119626         C588763A1ADE0FA5983F76
8 bits:         -35341100306444594726559813         E2C43B1D0D6F07D2CC1FBB
9 bits:         -17670550153222297363279907         F1621D8E86B783E9660FDD
10 bits:          -8835275076611148681639954          8B10EC7435BC1F4B307EE
11 bits:          -4417637538305574340819977          C588763A1ADE0FA5983F7
12 bits:          -2208818769152787170409989          E2C43B1D0D6F07D2CC1FB
13 bits:          -1104409384576393585204995          F1621D8E86B783E9660FD
14 bits:           -552204692288196792602498           8B10EC7435BC1F4B307E
15 bits:           -276102346144098396301249           C588763A1ADE0FA5983F
16 bits:           -138051173072049198150625           E2C43B1D0D6F07D2CC1F


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