Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert hexadecimal "string" into actual hexadecimal value in .NET? [duplicate]

Possible Duplicate:
How to convert numbers between hexadecimal and decimal in C#?

I need to be able to take a hexadecimal string and convert it into actual hexadecimal value in .NET. How do I do this?

For instance, in Delphi, you can take string of "FF" and add the dollar sign as follow to it.

tmpstr := '$'+ 'FF';

Then, convert tmpstr string variable into an integer to get the actual hexidecimal. The result would be 255.

like image 656
ThN Avatar asked Dec 04 '22 03:12

ThN


2 Answers

Assuming you are trying to convert your string to an int:

var i = Int32.Parse("FF", System.Globalization.NumberStyles.HexNumber)

Your example 1847504890 does not fit on an int, however. Use a longer type instead.

var i = Int64.Parse("1847504890", System.Globalization.NumberStyles.HexNumber)
like image 116
user703016 Avatar answered Apr 07 '23 03:04

user703016


Very simple:

int value = Convert.ToInt32("DEADBEEF", 16);

like image 35
Speed Of Light Avatar answered Apr 07 '23 01:04

Speed Of Light