Hex conversion help
-
Can someone advise me on how to convert hex conversion in C#? I am currently trying to get the string in a textbox, say "20" and convert it to its hex form 14, and then display it onto another textbox. Weiye, Chen When pursuing your dreams, don't forget to enjoy your life...
-
Can someone advise me on how to convert hex conversion in C#? I am currently trying to get the string in a textbox, say "20" and convert it to its hex form 14, and then display it onto another textbox. Weiye, Chen When pursuing your dreams, don't forget to enjoy your life...
From help (I did something similar to this) : Console.Write("{0:X}", 250); I'm not sure if you can do that directly to a string or if you need to use a StringBuffer class like I did. This is some code how I retreived color codes in individual colors (in bytes) and converted them to hex strings.
StringBuilder oBuffer = new StringBuilder(); string strColorCode = ""; byte byRed = 0; byte byGreen = 0; byte byBlue = 0; // Selected color can now be retreived by RGB components byRed = oColor.R; byGreen = oColor.G; byBlue = oColor.B; // Format string to get hex number for color strColorCode = "{0:x2}{1:x2}{2:x2}"; oBuffer.AppendFormat(strColorCode, byRed, byGreen, byBlue); return oBuffer.ToString();
There are only 10 types of people in this world....those that understand binary, and those that do not.
-
From help (I did something similar to this) : Console.Write("{0:X}", 250); I'm not sure if you can do that directly to a string or if you need to use a StringBuffer class like I did. This is some code how I retreived color codes in individual colors (in bytes) and converted them to hex strings.
StringBuilder oBuffer = new StringBuilder(); string strColorCode = ""; byte byRed = 0; byte byGreen = 0; byte byBlue = 0; // Selected color can now be retreived by RGB components byRed = oColor.R; byGreen = oColor.G; byBlue = oColor.B; // Format string to get hex number for color strColorCode = "{0:x2}{1:x2}{2:x2}"; oBuffer.AppendFormat(strColorCode, byRed, byGreen, byBlue); return oBuffer.ToString();
There are only 10 types of people in this world....those that understand binary, and those that do not.
I just found out how to do the conversion, thanks to your format string :
strColorCode = "{0:x2}{1:x2}{2:x2}";
This is what i did :short sh = System.Convert.ToInt16(tbTextBox.Text, 10); tbTextBox2.Text = String.Format("{0:x2}", sh);
Weiye, Chen When pursuing your dreams, don't forget to enjoy your life... -
Can someone advise me on how to convert hex conversion in C#? I am currently trying to get the string in a textbox, say "20" and convert it to its hex form 14, and then display it onto another textbox. Weiye, Chen When pursuing your dreams, don't forget to enjoy your life...
-
[using SWF;] int i = 20; txtBox1.Text = i.ToString(); txtBox2.Text = i.ToString("x"); Greets, Daniel
Thanks... This seems like a more straight forward method :-D Weiye, Chen When pursuing your dreams, don't forget to enjoy your life...