문제

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