Reputation: 533
I want to add two hexadecimal numbers in hex mode and result should also be hexadecimal. But the problem is I have a string "20010000" and int 0x400050, how should I add those to receive 0x20410050 ?
Ive tried int.Parse with various hex options but it always results as decimal addition.
Upvotes: 0
Views: 166
Reputation: 60143
Is this what you're looking for?
string aString = "20010000";
int a = Convert.ToInt32(aString, 16); // should be 536936448
int b = 0x400050; // should be 4194384
int sum = a + b; // should be 541130832
string sumString = sum.ToString("X"); // should be "20410050"
string sumStringWithPrefix = "0x" + subString; // should be "0x20410050"
Upvotes: 1