Hello!
I wonder how it would be possible to calculate using Unsigned 256 bit integers(uint256) in C#, Visual Studio 2019.
(A uint256 variable has a maximum value of Math.Pos(2,256) – 1)
I have looked at BigInteger but are not sure if this can be used somehow or if I need to use another solution or library of some sort?
The image shows code that is written in solidity and in that language it is possible to use uint256.
I have written down an example calculation which is my goal to do in C# somehow. I have just put uint256 as declaration to illustrate what I am trying to do.
How can we calculate this in C#?
It would be needed to show a working example of the below calculation exactly because if I change uint256 to BigInteger I get compile error on line 10 that says:
Operator '/' cannot be applied to operands of type 'BigInteger' and 'double'
I am not sure if this is possible either to do and that bigdouble5 return the correct number?double bigdouble5 = Math.Pow(2, 128)
Thank you!
uint256 bigint1 = 329974300448100608374211110737048701521;
uint256 bigint2 = 326010339881230390929338722651861109232;
uint256 bigint3 = 92097159224555409225;
int decimals = 18;
uint256 bigint4 = bigint1 - bigint2;
double bigdouble5 = Math.Pow(2, 128); //returns very large number
double bigdouble6 = Math.Pow(10, decimals);
double NUM = ((bigint4 - 0) / bigdouble5) * bigint3 / bigdouble6; //Returns a normal double value like: "0.8654" (this it not the correct result though)
Parts of original code from Solidity that I try to put in C#