c 中的字符串和int的condanation.从ASCII转换为十六进制
Concatanation of strings and ints in C++. Conversion from ASCII to HEX
我一直在墙上撞到墙上,尝试了许多不同的方法来做到这一点,但它们似乎都没有正常工作。
评论的线是我试图在C 中重写的C#中的代码。任何帮助将不胜感激。
void sendCommand(string command)
{
//Convert.ToString((8 * startBit) + "4" + command);
char buffer[50];
sprintf(buffer, "%d", (8 * startBit));
motor.printf("sendBuffer: %drn", buffer);
startBit = 1 - startBit;
motor.printf("%s%c%snr", buffer, "4", command);
return;
}
string strAcceleration(int acceleration)
{
//string accelerationHex = acceleration.ToString("X");
//accelerationHex = accelerationHex.PadLeft(8,'0');
char buffer[50];
sprintf(buffer, "%00000000X", acceleration);
motor.printf("acc: %s", buffer);
return buffer;
}
string strSpeed(int speed)
{
/*
string speedHex = null;
if (speed == 0) speedHex = "0";
else if (speed > 0) speedHex = speed.ToString("X");
else speedHex = 0xFFFFFFFF + speed.ToString("X");
if(speedHex.Length == 1) speedHex = "0000000" + speedHex;
if(speedHex.Length == 2) speedHex = "000000" + speedHex;
if(speedHex.Length == 3) speedHex = "00000" + speedHex;
return speedHex;
*/
}
谢谢
乔
我不知道您的C#代码是什么,但是第二个
sprintf(buffer, "%08X", acceleration);
看上去没有一百万英里。同样对于第一个
std::ostringstream buffer;
buffer << (8 * startBit) << "4" << command;
std::string motor = buffer.str();
看起来它已经接近您想要的。
相关文章:
- 在C++中使用 ASCII 代码将输入从小写转换为大写
- 我的程序将 26 个字母转换为 ascII 没有显示正确答案
- 我写的 ASCII 到二进制转换器C++向后显示二进制,如何使其正确显示?
- 我正在尝试编写将 ASCII 转换为十进制、添加并转换回 ASCII 的软件
- C++-将ASCII字符数组中可能的数值转换为字符的最简单方法
- 如何将ASCII数字转换为从文件中提取的整数
- 将非 ASCII 字符转换为英语对应字符C++
- 在Qt中将QString转换为ASCII值,反之亦然
- 输出使用 cout 转换为 ASCII 的文本时输出格式不正确,C++
- 如何在不将其转换为 ASCII 字符的情况下显示 QByteArray 的十六进制值
- 如何使用 ASCII 转换使用字符堆栈计算后缀表达式
- C++将 ASCII 转换为莫尔斯电码
- 找到排列的ASCII转换
- c 中的字符串和int的condanation.从ASCII转换为十六进制
- 如何从ASCII转换为字符串或符号
- 从 ASCII 转换回字符
- 将ascii转换为char
- 我如何从ASCII转换到十六进制值,也增加char指针
- 使用c++将ASCII转换成十六进制的无符号int形式
- 将ASCII转换为Unsigned Int,反之亦然