在 Arduino 上将整数/十进制转换为十六进制? [英] Convert integer/decimal to hex on an Arduino?

查看:204
本文介绍了在 Arduino 上将整数/十进制转换为十六进制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将整数或十进制变量转换为十六进制字符串?我可以做相反的事情(将十六进制转换为整数),但我想不出其他方式.

How can an integer or decimal variable be converted into a hex string? I can do the opposite (convert hex to int) but I can't figure out the other way.

这是用于数组中的 Serial.print() 十六进制值.

This is for Serial.print() hex values in an array.

推荐答案

查看 Arduino String 教程 此处.下面的代码取自该示例.

Take a look at the Arduino String tutorial here. The code below was taken from that example.

// using an int and a base (hexadecimal):
stringOne =  String(45, HEX);   
// prints "2d", which is the hexadecimal version of decimal 45:
Serial.println(stringOne);  

该页面上还有很多其他示例,但我认为对于浮点数,您必须自己动手.

There are plenty of other examples on that page, though I think for floating point numbers you'll have to roll your own.

这篇关于在 Arduino 上将整数/十进制转换为十六进制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆