This is used for sending Data to receiving mDot
Dependencies: libmDot-dev-mbed5-deprecated ISL29011
Fork of mdot-examples by
itoa.cpp
- Committer:
- SDesign2018
- Date:
- 2017-12-01
- Revision:
- 5:c9ab5062cfc3
File content as of revision 5:c9ab5062cfc3:
#include <string.h> #include "itoa.h" using namespace std; // Implementation of itoa() char* itoa(int num, char* str, int base) { int i = 0; bool isNegative = false; /* Handle 0 explicitely, otherwise empty string is printed for 0 */ if (num == 0) { str[i++] = '0'; str[i] = '\0'; return str; } // In standard itoa(), negative numbers are handled only with // base 10. Otherwise numbers are considered unsigned. if (num < 0 && base == 10) { isNegative = true; num = -num; } // Process individual digits while (num != 0) { int rem = num % base; str[i++] = (rem > 9)? (rem-10) + 'a' : rem + '0'; num = num/base; } // If number is negative, append '-' if (isNegative) str[i++] = '-'; str[i] = '\0'; // Append string terminator // Reverse the string reverse(str); return str; } /* ** reverse string in place */ void reverse(char *s){ char *j; int c; j = s + strlen(s) - 1; while(s < j) { c = *s; *s++ = *j; *j-- = c; } }