Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.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
在Arduino上将整数/十进制转换为十六进制?_Arduino - Fatal编程技术网

在Arduino上将整数/十进制转换为十六进制?

在Arduino上将整数/十进制转换为十六进制?,arduino,Arduino,如何将整数或十进制变量转换为十六进制字符串?我可以做相反的事情(将十六进制转换为int),但我不能想出另一种方法 这适用于数组中的十六进制值。请看Arduino字符串教程。下面的代码取自该示例 // using an int and a base (hexadecimal): stringOne = String(45, HEX); // prints "2d", which is the hexadecimal version of decimal 45: Serial.println

如何将整数或十进制变量转换为十六进制字符串?我可以做相反的事情(将十六进制转换为int),但我不能想出另一种方法


这适用于数组中的十六进制值。

请看Arduino字符串教程。下面的代码取自该示例

// using an int and a base (hexadecimal):
stringOne =  String(45, HEX);   
// prints "2d", which is the hexadecimal version of decimal 45:
Serial.println(stringOne);  
该页面上还有很多其他示例,不过我认为对于浮点数,您必须自己滚动。

该库提供了一种内置的方法:

#include <Streaming.h>
...
Serial << "45 in hex is " << _HEX(45) << endl;
#包括
...

串行有一个简单的解决方案,只需使用:

Serial.print(yourVariable, HEX);

只是确认一下Nathan关于浮点的说法。默认情况下,支持打印出浮点的代码库被认为太大,无法包含在内。一个简单的解决方案是将你的数字乘以100左右,然后打印成整数。