Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

parseInt works in JavaScript, but not in C#

I’m trying to convert this JavaScript code to C#. It is a hexadecimal string that is the value of a crypto token.

Here is what works in JavaScript:

parseInt("0x0000000000000000000000000000000000000000000000056bc75e2d63100000", 16)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here is what I have tried in C#:

var result = Int16.Parse("0x0000000000000000000000000000000000000000000000056bc75e2d63100000");

I get the error Input string was not in a correct format. What am I doing wrong?

>Solution :

the number is too large for int.

void Main()
{
    string x = "0x0000000000000000000000000000000000000000000000056bc75e2d63100000";
    new System.ComponentModel.Int128Converter().ConvertFromString(x).Dump();
}

result would be 100000000000000000000

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading