convert HEX string to Decimal in arduino

随声附和 提交于 2019-11-29 15:47:44

Drop all that code, and just use 'strtol' from the standard library.

 #include <stdlib.h>
 long strtol (const char *__nptr, char **__endptr, int __base)

For your use:

long decimal_answer = strtol("0005607947", NULL, 16);

You are trying to store the value 90208583 in an int. Arduino has a 2 byte int size meaning that the largest number you can store is 2^16-1 (65535). You have a couple of options:

  1. Use an unsigned int
    • min number: 0
    • max number: 4,294,967,295
    • cons: can only be used for positive numbers
  2. Use a long int
    • min number: -2,147,483,648
    • max number: 2,147,483,647
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!