Search code examples
c#.netint128

What type should I use for a 128-bit number in in .NET?


I need to do some large integer math. Are there any classes or structs out there that represent a 128-bit integer and implement all of the usual operators?

BTW, I realize that decimal can be used to represent a 96-bit int.


Solution

  • It's here in System.Numerics. "The BigInteger type is an immutable type that represents an arbitrarily large integer whose value in theory has no upper or lower bounds."

    var i = System.Numerics.BigInteger.Parse("10000000000000000000000000000000");