다음을 통해 공유


BigInteger.LeftShift(BigInteger, Int32) 연산자

정의

BigInteger 값을 지정된 비트 수만큼 왼쪽으로 이동합니다.

public:
 static System::Numerics::BigInteger operator <<(System::Numerics::BigInteger value, int shift);
public:
 static System::Numerics::BigInteger operator <<(System::Numerics::BigInteger value, int shift) = System::Numerics::IShiftOperators<System::Numerics::BigInteger, int, System::Numerics::BigInteger>::op_LeftShift;
public static System.Numerics.BigInteger operator << (System.Numerics.BigInteger value, int shift);
static member ( <<< ) : System.Numerics.BigInteger * int -> System.Numerics.BigInteger
Public Shared Operator << (value As BigInteger, shift As Integer) As BigInteger

매개 변수

value
BigInteger

비트를 이동할 값입니다.

shift
Int32

value를 왼쪽으로 이동할 비트 수입니다.

반환

지정된 비트 수만큼 왼쪽으로 이동한 값입니다.

구현

설명

메서드는 LeftShift 값에 대한 비트 왼쪽 시프트 연산자의 연산을 BigInteger 정의합니다. 다음과 같은 코드를 사용하도록 설정합니다.

BigInteger number = BigInteger.Parse("-9047321678449816249999312055");
Console.WriteLine("Shifting {0} left 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"));
}
// The example displays the following output:
//    Shifting -9047321678449816249999312055 left by:
//      0 bits:       -9047321678449816249999312055       E2C43B1D0D6F07D2CC1FBB49
//      1 bits:      -18094643356899632499998624110       C588763A1ADE0FA5983F7692
//      2 bits:      -36189286713799264999997248220       8B10EC7435BC1F4B307EED24
//      3 bits:      -72378573427598529999994496440      F1621D8E86B783E9660FDDA48
//      4 bits: -1.4475714685519705999998899288E+29      E2C43B1D0D6F07D2CC1FBB490
//      5 bits: -2.8951429371039411999997798576E+29      C588763A1ADE0FA5983F76920
//      6 bits: -5.7902858742078823999995597152E+29      8B10EC7435BC1F4B307EED240
//      7 bits:  -1.158057174841576479999911943E+30     F1621D8E86B783E9660FDDA480
//      8 bits: -2.3161143496831529599998238861E+30     E2C43B1D0D6F07D2CC1FBB4900
//      9 bits: -4.6322286993663059199996477722E+30     C588763A1ADE0FA5983F769200
//     10 bits: -9.2644573987326118399992955443E+30     8B10EC7435BC1F4B307EED2400
//     11 bits: -1.8528914797465223679998591089E+31    F1621D8E86B783E9660FDDA4800
//     12 bits: -3.7057829594930447359997182177E+31    E2C43B1D0D6F07D2CC1FBB49000
//     13 bits: -7.4115659189860894719994364355E+31    C588763A1ADE0FA5983F7692000
//     14 bits: -1.4823131837972178943998872871E+32    8B10EC7435BC1F4B307EED24000
//     15 bits: -2.9646263675944357887997745742E+32   F1621D8E86B783E9660FDDA48000
//     16 bits: -5.9292527351888715775995491484E+32   E2C43B1D0D6F07D2CC1FBB490000
    let number = BigInteger.Parse "-9047321678449816249999312055"
    printfn $"Shifting {number} left by:"

    for ctr = 0 to 16 do
        let newNumber = number <<< ctr
        printfn $" {ctr, 2} bits: {newNumber, 35} {newNumber:X}"
// The example displays the following output:
//    Shifting -9047321678449816249999312055 left by:
//      0 bits:       -9047321678449816249999312055       E2C43B1D0D6F07D2CC1FBB49
//      1 bits:      -18094643356899632499998624110       C588763A1ADE0FA5983F7692
//      2 bits:      -36189286713799264999997248220       8B10EC7435BC1F4B307EED24
//      3 bits:      -72378573427598529999994496440      F1621D8E86B783E9660FDDA48
//      4 bits: -1.4475714685519705999998899288E+29      E2C43B1D0D6F07D2CC1FBB490
//      5 bits: -2.8951429371039411999997798576E+29      C588763A1ADE0FA5983F76920
//      6 bits: -5.7902858742078823999995597152E+29      8B10EC7435BC1F4B307EED240
//      7 bits:  -1.158057174841576479999911943E+30     F1621D8E86B783E9660FDDA480
//      8 bits: -2.3161143496831529599998238861E+30     E2C43B1D0D6F07D2CC1FBB4900
//      9 bits: -4.6322286993663059199996477722E+30     C588763A1ADE0FA5983F769200
//     10 bits: -9.2644573987326118399992955443E+30     8B10EC7435BC1F4B307EED2400
//     11 bits: -1.8528914797465223679998591089E+31    F1621D8E86B783E9660FDDA4800
//     12 bits: -3.7057829594930447359997182177E+31    E2C43B1D0D6F07D2CC1FBB49000
//     13 bits: -7.4115659189860894719994364355E+31    C588763A1ADE0FA5983F7692000
//     14 bits: -1.4823131837972178943998872871E+32    8B10EC7435BC1F4B307EED24000
//     15 bits: -2.9646263675944357887997745742E+32   F1621D8E86B783E9660FDDA48000
//     16 bits: -5.9292527351888715775995491484E+32   E2C43B1D0D6F07D2CC1FBB490000
Dim number As BigInteger = BigInteger.Parse("-9047321678449816249999312055")
Console.WriteLine("Shifting {0} left by:", number)
For ctr As Integer = 0 To 16
   Dim newNumber As BigInteger = number << ctr
   Console.WriteLine(" {0,2} bits: {1,35} {2,30}", ctr, newNumber, newNumber.ToString("X"))
Next
' The example displays the following output:
'    Shifting -9047321678449816249999312055 left by:
'      0 bits:       -9047321678449816249999312055       E2C43B1D0D6F07D2CC1FBB49
'      1 bits:      -18094643356899632499998624110       C588763A1ADE0FA5983F7692
'      2 bits:      -36189286713799264999997248220       8B10EC7435BC1F4B307EED24
'      3 bits:      -72378573427598529999994496440      F1621D8E86B783E9660FDDA48
'      4 bits: -1.4475714685519705999998899288E+29      E2C43B1D0D6F07D2CC1FBB490
'      5 bits: -2.8951429371039411999997798576E+29      C588763A1ADE0FA5983F76920
'      6 bits: -5.7902858742078823999995597152E+29      8B10EC7435BC1F4B307EED240
'      7 bits:  -1.158057174841576479999911943E+30     F1621D8E86B783E9660FDDA480
'      8 bits: -2.3161143496831529599998238861E+30     E2C43B1D0D6F07D2CC1FBB4900
'      9 bits: -4.6322286993663059199996477722E+30     C588763A1ADE0FA5983F769200
'     10 bits: -9.2644573987326118399992955443E+30     8B10EC7435BC1F4B307EED2400
'     11 bits: -1.8528914797465223679998591089E+31    F1621D8E86B783E9660FDDA4800
'     12 bits: -3.7057829594930447359997182177E+31    E2C43B1D0D6F07D2CC1FBB49000
'     13 bits: -7.4115659189860894719994364355E+31    C588763A1ADE0FA5983F7692000
'     14 bits: -1.4823131837972178943998872871E+32    8B10EC7435BC1F4B307EED24000
'     15 bits: -2.9646263675944357887997745742E+32   F1621D8E86B783E9660FDDA48000
'     16 bits: -5.9292527351888715775995491484E+32   E2C43B1D0D6F07D2CC1FBB490000

참고

정수 기본 형식을 사용하는 비트 왼쪽 시프트 작업과 달리 메서드는 LeftShift 원래 BigInteger 값의 기호를 유지합니다.

사용자 지정 연산자를 지원하지 않는 언어는 를 곱 valueBigInteger.Pow(2, shift)하여 비트 왼쪽 시프트 작업을 수행할 수 있습니다. 다음 예제에서는 결과가 이 연산자를 사용한 결과와 동일하다는 것을 보여줍니다.

BigInteger number = BigInteger.Parse("-9047321678449816249999312055");
Console.WriteLine("Shifting {0} left by:", number);
for (int ctr = 0; ctr <= 16; ctr++)
{
   BigInteger newNumber = BigInteger.Multiply(number, BigInteger.Pow(2, ctr));
   Console.WriteLine(" {0,2} bits: {1,35} {2,30}",
                     ctr, newNumber, newNumber.ToString("X"));
}
// The example displays the following output:
//    Shifting -9047321678449816249999312055 left by:
//      0 bits:       -9047321678449816249999312055       E2C43B1D0D6F07D2CC1FBB49
//      1 bits:      -18094643356899632499998624110       C588763A1ADE0FA5983F7692
//      2 bits:      -36189286713799264999997248220       8B10EC7435BC1F4B307EED24
//      3 bits:      -72378573427598529999994496440      F1621D8E86B783E9660FDDA48
//      4 bits: -1.4475714685519705999998899288E+29      E2C43B1D0D6F07D2CC1FBB490
//      5 bits: -2.8951429371039411999997798576E+29      C588763A1ADE0FA5983F76920
//      6 bits: -5.7902858742078823999995597152E+29      8B10EC7435BC1F4B307EED240
//      7 bits:  -1.158057174841576479999911943E+30     F1621D8E86B783E9660FDDA480
//      8 bits: -2.3161143496831529599998238861E+30     E2C43B1D0D6F07D2CC1FBB4900
//      9 bits: -4.6322286993663059199996477722E+30     C588763A1ADE0FA5983F769200
//     10 bits: -9.2644573987326118399992955443E+30     8B10EC7435BC1F4B307EED2400
//     11 bits: -1.8528914797465223679998591089E+31    F1621D8E86B783E9660FDDA4800
//     12 bits: -3.7057829594930447359997182177E+31    E2C43B1D0D6F07D2CC1FBB49000
//     13 bits: -7.4115659189860894719994364355E+31    C588763A1ADE0FA5983F7692000
//     14 bits: -1.4823131837972178943998872871E+32    8B10EC7435BC1F4B307EED24000
//     15 bits: -2.9646263675944357887997745742E+32   F1621D8E86B783E9660FDDA48000
//     16 bits: -5.9292527351888715775995491484E+32   E2C43B1D0D6F07D2CC1FBB490000
    let number = BigInteger.Parse "-9047321678449816249999312055"
    printfn $"Shifting {number} left by:"

    for ctr = 0 to 16 do
        let newNumber = number * BigInteger.Pow(2, ctr)
        printfn $" {ctr, 2} bits: {newNumber, 35} {newNumber:X}"
// The example displays the following output:
//    Shifting -9047321678449816249999312055 left by:
//      0 bits:       -9047321678449816249999312055       E2C43B1D0D6F07D2CC1FBB49
//      1 bits:      -18094643356899632499998624110       C588763A1ADE0FA5983F7692
//      2 bits:      -36189286713799264999997248220       8B10EC7435BC1F4B307EED24
//      3 bits:      -72378573427598529999994496440      F1621D8E86B783E9660FDDA48
//      4 bits: -1.4475714685519705999998899288E+29      E2C43B1D0D6F07D2CC1FBB490
//      5 bits: -2.8951429371039411999997798576E+29      C588763A1ADE0FA5983F76920
//      6 bits: -5.7902858742078823999995597152E+29      8B10EC7435BC1F4B307EED240
//      7 bits:  -1.158057174841576479999911943E+30     F1621D8E86B783E9660FDDA480
//      8 bits: -2.3161143496831529599998238861E+30     E2C43B1D0D6F07D2CC1FBB4900
//      9 bits: -4.6322286993663059199996477722E+30     C588763A1ADE0FA5983F769200
//     10 bits: -9.2644573987326118399992955443E+30     8B10EC7435BC1F4B307EED2400
//     11 bits: -1.8528914797465223679998591089E+31    F1621D8E86B783E9660FDDA4800
//     12 bits: -3.7057829594930447359997182177E+31    E2C43B1D0D6F07D2CC1FBB49000
//     13 bits: -7.4115659189860894719994364355E+31    C588763A1ADE0FA5983F7692000
//     14 bits: -1.4823131837972178943998872871E+32    8B10EC7435BC1F4B307EED24000
//     15 bits: -2.9646263675944357887997745742E+32   F1621D8E86B783E9660FDDA48000
//     16 bits: -5.9292527351888715775995491484E+32   E2C43B1D0D6F07D2CC1FBB490000
Dim number As BigInteger = BigInteger.Parse("-9047321678449816249999312055")
Console.WriteLine("Shifting {0} left by:", number)
For ctr As Integer = 0 To 16
   Dim newNumber As BigInteger = BigInteger.Multiply(number, BigInteger.Pow(2, ctr))
   Console.WriteLine(" {0,2} bits: {1,35} {2,30}", 
                     ctr, newNumber, newNumber.ToString("X"))
Next
' The example displays the following output:
'    Shifting -9047321678449816249999312055 left by:
'      0 bits:       -9047321678449816249999312055       E2C43B1D0D6F07D2CC1FBB49
'      1 bits:      -18094643356899632499998624110       C588763A1ADE0FA5983F7692
'      2 bits:      -36189286713799264999997248220       8B10EC7435BC1F4B307EED24
'      3 bits:      -72378573427598529999994496440      F1621D8E86B783E9660FDDA48
'      4 bits: -1.4475714685519705999998899288E+29      E2C43B1D0D6F07D2CC1FBB490
'      5 bits: -2.8951429371039411999997798576E+29      C588763A1ADE0FA5983F76920
'      6 bits: -5.7902858742078823999995597152E+29      8B10EC7435BC1F4B307EED240
'      7 bits:  -1.158057174841576479999911943E+30     F1621D8E86B783E9660FDDA480
'      8 bits: -2.3161143496831529599998238861E+30     E2C43B1D0D6F07D2CC1FBB4900
'      9 bits: -4.6322286993663059199996477722E+30     C588763A1ADE0FA5983F769200
'     10 bits: -9.2644573987326118399992955443E+30     8B10EC7435BC1F4B307EED2400
'     11 bits: -1.8528914797465223679998591089E+31    F1621D8E86B783E9660FDDA4800
'     12 bits: -3.7057829594930447359997182177E+31    E2C43B1D0D6F07D2CC1FBB49000
'     13 bits: -7.4115659189860894719994364355E+31    C588763A1ADE0FA5983F7692000
'     14 bits: -1.4823131837972178943998872871E+32    8B10EC7435BC1F4B307EED24000
'     15 bits: -2.9646263675944357887997745742E+32   F1621D8E86B783E9660FDDA48000
'     16 bits: -5.9292527351888715775995491484E+32   E2C43B1D0D6F07D2CC1FBB490000

적용 대상

추가 정보