Instantiate BigInteger values : BigInteger « Data Types « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » Data Types » BigIntegerScreenshots 
Instantiate BigInteger values
 


using System;
using System.Numerics;

public class Example
{
   public static void Main()
   {
        BigInteger positiveValue = BigInteger.Parse("9999999999999999999999999");
        BigInteger negativeValue = BigInteger.Add(-Int64.MaxValue, -60000)
        BigInteger positiveValue2, negativeValue2;
        
        // Create two byte arrays.
        byte[] positiveBytes = positiveValue.ToByteArray();
        byte[] negativeBytes = negativeValue.ToByteArray();
        
        // Instantiate new BigInteger from negativeBytes array.
        Console.Write("Converted {0:N0} to the byte array ", negativeValue);
        foreach (byte byteValue in negativeBytes)
           Console.Write("{0:X2} ", byteValue);

        negativeValue2 = new BigInteger(negativeBytes);
        Console.WriteLine("Converted the byte array to {0:N0}", negativeValue2);
        
        // Instantiate new BigInteger from positiveBytes array.
        Console.Write("Converted {0:N0} to the byte array ", positiveValue);
        foreach (byte byteValue in positiveBytes)
           Console.Write("{0:X2} ", byteValue);
        
        positiveValue2 = new BigInteger(positiveBytes);
        Console.WriteLine("Converted the byte array to {0:N0}", positiveValue2);
   }
}

   
  
Related examples in the same category
1.Create BigInteger using the values in a byte array.
2.Initializes a new instance of the BigInteger structure using a Decimal value.
3.Divides one BigInteger value by another, returns the result, and returns the remainder in an output parameter.
4.Finds the greatest common divisor of two BigInteger values.
5.Increments a BigInteger value by 1.
6.Shifts a BigInteger value a specified number of bits to the left.
7.Returns the natural (base e) logarithm of a specified number.
8.Returns the larger of two BigInteger values.
9.Returns the smaller of two BigInteger values.
10.Performs modulus division on a number raised to the power of another number.
11.Converts the string representation of a number to its BigInteger equivalent.
12.Converts string in a specified culture-specific format to BigInteger
13.NumberFormatInfo and BigIntegerParse
14.Converts string in a specified style to BigInteger
15.NumberStyles and BigInteger parse
16.Raises a BigInteger value to the power of a specified value.
17.Performs integer division on two BigInteger values and returns the remainder.
18.Converts a BigInteger value to a byte array.
19.Converts BigInteger to string using the specified culture-specific formatting information.
20.Converts BigInteger to string using the specified format.
21.Converts BigInteger to string using culture-specific format information.
22.Converts BigInteger to string with ToString method
23.Tries to convert string to BigInteger
24.Tries to convert string in style and culture-specific format to BigInteger
25.NumberStyles and TryParse
26.Negates a specified BigInteger value.
27.Defines an explicit conversion of a BigInteger object to an unsigned byte value.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.