将hex命令传递给c函数

时间:2016-02-18 16:52:28

标签: c hex uart

在下面的函数声明中,对于mcu上的uart write,我可以传递十六进制命令吗?

uart_write(const uart_t uart, const uint8_t data);

uart_write(uart_1, 0x56);

2 个答案:

答案 0 :(得分:1)

是的,你可以。但是,不要说pass a hex command,而是说pass the value using hex representation更为正确。

反正

uart_write(uart_1, 0x56);

相同
uart_write(uart_1, 86);  // 86 == 5 * 16 + 6

可以以多种格式/表示形式给出整数 - 编译器只是将值转换为适合编译器的表示形式。也许这对你来说很有意思:http://www.cplusplus.com/doc/hex/

答案 1 :(得分:1)

如果您的意思是十六进制数字,那么您可以。要写入十六进制数字,请务必在其前面加0x。您还可以在前面加上0

来编写八进制(基数为8)的数字
  • 0x56 Hexadecimal 56
  • 011 Octal 11