Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 将十六进制转换为整数_String_C++ Cli_Int_Hex - Fatal编程技术网

String 将十六进制转换为整数

String 将十六进制转换为整数,string,c++-cli,int,hex,String,C++ Cli,Int,Hex,我已经看到了很多关于这个问题的答案,但我似乎无法找到任何答案。我想我对变量类型感到困惑。我有一个来自NetworkStream的输入,它将十六进制代码放入字符串^。我需要把这个字符串的一部分转换成一个数字(大概是int),这样我就可以添加一些算术,然后在表单上输出reult。到目前为止,我掌握的代码是: String^msg;//稍后填充,例如“A55A6B0550000000FFFBDE0030C8” 字符串测试; //我已选择了字符串的相关部分,例如5A test=msg->Substrin

我已经看到了很多关于这个问题的答案,但我似乎无法找到任何答案。我想我对变量类型感到困惑。我有一个来自NetworkStream的输入,它将十六进制代码放入字符串^。我需要把这个字符串的一部分转换成一个数字(大概是int),这样我就可以添加一些算术,然后在表单上输出reult。到目前为止,我掌握的代码是:

String^msg;//稍后填充,例如“A55A6B0550000000FFFBDE0030C8”
字符串测试;
//我已选择了字符串的相关部分,例如5A
test=msg->Substring(2,2);
//我尝试了许多不同的方法来提取
//子串。以下是其中一些:
std::stringstream-ss;
hexInt=0;
//如果测试是字符串,而不是字符串^。
ss textBox1->AppendText(“经过一点数学运算后显示数值”);
在此方面的任何帮助都将不胜感激。
克里斯这有帮助吗

String^ hex = L"5A";
int converted = System::Convert::ToInt32(hex, 16);
MSDN上提供了用于转换静态方法的

<>你需要停止考虑使用托管类型的标准C++库。.Net BCL真的很好…

希望这有帮助:

/*
the method demonstrates converting hexadecimal values,
which are broken into low and high bytes.
*/
int main(){ 
//character buffer
char buf[1];
buf[0]= 0x06; //buffer initialized to some hex value
buf[1]= 0xAE; //buffer initialized to some hex value
int number=0;  

//number generated by binary shift of high byte and its OR with low byte
number = 0xFFFF&((buf[1]<<8)|buf[0]);

printf("%x",number);              //this prints AE06
printf(“%d”,number);              //this prints the integer equivalent

getch();
}
/*
该方法演示如何转换十六进制值,
分为低字节和高字节。
*/
int main(){
//字符缓冲区
char-buf[1];
buf[0]=0x06;//缓冲区初始化为某个十六进制值
buf[1]=0xAE;//缓冲区初始化为某个十六进制值
整数=0;
//由高位字节及其或低位字节的二进制移位生成的数字

C++.0[bxf]((1),不是C++。(C++中没有<代码>字符串^ < /Cord>)。我相信这是C++ + CLI,所以我把标签改成了。如果我错了请纠正我。这个数字看起来太大了,不能适应int。我只想要两个字符部分,而不是整个28。CheersThat的完美欢呼。我没有意识到我在使用C++库。