【问题标题】:passing hex command to c function [closed]将十六进制命令传递给c函数[关闭]
【发布时间】:2016-02-18 16:52:28
【问题描述】:

在下面的 uart write on a mcu 的函数声明中,我可以传递一个十六进制命令吗?

uart_write(const uart_t uart, const uint8_t data);

uart_write(uart_1, 0x56);

【问题讨论】:

  • “十六进制命令”是什么意思? 0x56 是一个十六进制整数常量。
  • 您正在为十六进制整数使用正确的文字。你到底想问什么?

标签: c hex uart


【解决方案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/

【讨论】:

    【解决方案2】:

    如果您的意思是十六进制数,是的,您可以。要写入十六进制数,请务必在其前面加上0x。您还可以在八进制(以 8 为基数)前加上 0

    • 0x56十六进制 56
    • 011 八进制 11

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-13
      • 2016-07-02
      • 1970-01-01
      • 2021-06-23
      • 1970-01-01
      • 1970-01-01
      • 2022-06-29
      • 1970-01-01
      相关资源
      最近更新 更多