C# BigInteger LeftShift

Description

BigInteger LeftShift Shifts a BigInteger value a specified number of bits to the left.

Syntax

BigInteger.LeftShift has the following syntax.


public static BigInteger operator <<(
  BigInteger value,
  int shift
)

Parameters

BigInteger.LeftShift has the following parameters.

  • value - The value whose bits are to be shifted.
  • shift - The number of bits to shift value to the left.

Returns

BigInteger.LeftShift method returns A value that has been shifted to the left by the specified number of bits.

Example


//  www .  jav  a2 s .  co  m
using System;
using System.IO;
using System.Numerics;

public class Example
{
   public static void Main()
   {
        BigInteger number = BigInteger.Parse("-12312312312312312312312");
        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"));
        }
        number = BigInteger.Parse("-1232123321231231231231");
        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 code above generates the following result.





















Home »
  C# Tutorial »
    System.Numerics »




BigInteger
Complex