Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

converting string to uint

I am trying to read in a hex value from a text box and then put it in a uint, this is the code:

UInt32 x = Convert.ToUInt32(location_txtbox.ToString());

Why, I want to pass x to some unmanaged code and the function header requires a DWORD.

I'm getting an 'input string was not in correct format error? I am trying to input values such as 0x7c or 0x777 but I keep getting errors?

Thanks.

like image 831
flavour404 Avatar asked Nov 29 '22 17:11

flavour404


1 Answers

Use this overload of Convert.ToUInt32 where you specify the base of the conversion. It should work with or without the leading "0x".

UInt32 x = Convert.ToUInt32(location_txtbox.Text, 16);
like image 193
Jeff Mercado Avatar answered Dec 02 '22 08:12

Jeff Mercado