将十进制文本框条目转换为十六进制以输出到另一个文本框 [英] Converting a Decimal Textbox Entry to Hexadecimal to output to another Textbox
问题描述
大家好,
我正在尝试为我的串口通信程序设计一个十进制到十六进制转换器。我遇到了一个绊脚石,我遇到了如何将文本框值(用户生成多达99个)输入到char数组中的问题。非常感谢任何和所有帮助。
我应该如何将文本框值存储到char数组中?
这是在解决它之前有效的代码(授予0x3F是这里唯一的输出):
int i = 0;
char integer_string [] =63; // 63是必须根据用户输入到恰当名为dec的文本框中的值而变化的值。
char hex_string [10] =;
i = atoi(integer_string);
sprintf(hex_string,0x%02X,i);
hex-> Text = gcnew String(hex_string);
对于在家中关注的任何人,以下是具有解决方案的代码的最终结果:
int i = 0;
i = Int32 :: Parse(dec-> Text);
char hex_string [10] =;
sprintf(hex_string,0x%02X,i);
hex-> Text = gcnew String(hex_string);
如果不通过字符数组,您可以使用:
i = int32 :: Parse(dec-> Text); // 假设您的'十进制'TextBox名称为'dec'
Hello all,
I am trying to craft a Decimal to Hexadecimal converter for my serial port communication program. I have hit one stumbling block, I am having issues figuring out how to input the textbox value (user generated up to 99) into the char array. Any and all help is greatly appreciated.
How should I go about storing the textbox value into the char array?
Here is the code that works before mucking it up (granted "0x3F" is the only output here):
int i=0; char integer_string[] = "63"; //The 63 is the value that must change based on the entry from the user into the textbox aptly named "dec". char hex_string[10] = ""; i = atoi (integer_string); sprintf (hex_string, "0x%02X", i); hex->Text = gcnew String(hex_string);
For anyone following at home, here is the end result of the code with solution in place:
int i=0; i = Int32::Parse(dec->Text); char hex_string[10] = ""; sprintf (hex_string, "0x%02X", i); hex->Text = gcnew String(hex_string);
Without passing through the character array, you might use:
i = int32::Parse(dec->Text); // assuming your 'decimal' TextBox name is 'dec'
这篇关于将十进制文本框条目转换为十六进制以输出到另一个文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!