简体   繁体   中英

C# Writing hex string from textbox as bytes

I am trying to convert hex values from a textbox string (ie ffff) to 0xffff as a INT (This way I can use binary writer to write FFFF as 2 bytes in a file).

I actually used this:

string hextoconvert = Convert.ToInt32(textBox1.Text).ToString("X8");

(But again wasn't sure how to convert the string 0002045E to int 0x0002045E (as 4 bytes)). If that isn't the right idea then what should I use to convert hex values that the user puts in a textbox TO BYTES?

int.Parse(hexString, System.Globalization.NumberStyles.AllowHexSpecifier);

这很奏效,谢谢m.rogalski!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM