【发布时间】:2011-10-04 23:23:06
【问题描述】:
我正在尝试将 8 位微控制器(PIC)上的 C 整数分解为其 ASCII 等效字符。
例如: 将 982 转换为 '9','8','2'
到目前为止,我想出的一切似乎都是蛮力的。这是我现在基本上在做的主要思想:
if( (10 <= n) && (n < 100) ) {
// isolate and update the first order of magnitude
digit_0 = (n % 10);
// isolate and update the second order of magnitude
switch( n - (n % 10) ) {
case 0:
digit_1 = 0;
break;
case 10:
digit_1 = 1;
break;
...
然后我有另一个函数,只需将 0b00110000(48 进制)添加到我的每个数字。
我一直无法找到任何 C 函数来为我做这件事或我自己做得很好。
提前感谢您的帮助!
【问题讨论】:
标签: c integer ascii character pic