質問

I need help to divide hex characters something like this. I know this does not work. If i enter 418 my answer should be 20C. Im using C# Thanks

private void button23_Click(object sender, EventArgs e)  //calculator
    {

        {
            offset = textBox10.Text;

           offset hex / 2 = offset2


            textBox11.Text = offset2;

        }
    }
役に立ちましたか?

解決

NumberStyles is a bit esoteric but it's how you do it:

int offset = int.Parse(textBox10.Text, System.Globalization.NumberStyles.HexNumber);
int offset2 = offset / 2;
textBox11.Text = String.Format("{0:X}", offset2);

Of course, you might need more processing and validation of the user input. Look at int.TryParse and different int sizes (e.g. Int64), too.

他のヒント

You can use int.Parse to convert your hex string to an int, perform any arithmetic operation you require on it, then use ToString to convert it back to a hex string.

string offset = textBox10.Text;
int val = int.Parse(offset, System.Globalization.NumberStyles.HexNumber);
int div = val / 2;
string offset2 = div.ToString("X");
textBox11.Text = offset2;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top