Parse decimal from textblock (string) and convert to hexidecimal

220 views Asked by At

Okay so lets say I input this in to a rich textbox:

private void noRecoilOn()
{
    this.Jtag.WriteUInt32(2200480928u, 1024u);
}
private void noRecoilOff()
{
    this.Jtag.WriteUInt32(2200480928u, 0u);
}

I want to be able to parse out the decimals and convert it to Hexadecimal like so:

private void noRecoilOn()
{
    this.Jtag.WriteUInt32(0x8328ACA0, 0x400);
}
private void noRecoilOff()
{
    this.Jtag.WriteUInt32(0x8328ACA0, 0x0);
}

This is just a quick example but the real things I will be converting will be whole blocks of code with many different decimals that need to be converted, not just "2200480928u".

How would I go about doing this. I have no idea

1

There are 1 answers

4
Harrison On

I would suggest looking at How to: Convert Between Hexadecimal Strings and Numeric Types (C# Programming Guide)

In addition the ToString() has a format to write to Hex and UInt32.Parse can be provided an IFormat

uint num = 2200480928u;

// Converts the uint to a hex string
string hex = num.ToString("X");


// Convert the hex string back to the number
uint number = UInt32.Parse(hex, System.Globalization.NumberStyles.HexNumber);