Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FatFileSystemCpp mbed PowerControl USBHostLite
utils.cpp
00001 #include <mbed.h> 00002 00003 void itoa(int num, int type, char *buf) 00004 { 00005 char *c = buf; 00006 char *start, *stop; 00007 int base = 10, digit; 00008 if (type == 'd' && num < 0) { 00009 *c++ = '-'; 00010 num = -num; 00011 } 00012 00013 if (type == 'x') { 00014 base = 16; 00015 *c++ = '0'; 00016 *c++ = 'x'; 00017 } 00018 start = c; 00019 00020 /* create string from number */ 00021 do { 00022 digit = num % base; 00023 *c++ = digit > 9 ? 'A' + digit - 10 : '0' + digit; 00024 } while (num /= base); 00025 00026 *c = '\0'; 00027 stop = c - 1; 00028 00029 /* string is reversed, reverse it to the correct form */ 00030 while (start < stop) { 00031 char tmp = *start; 00032 *start++ = *stop; 00033 *stop-- = tmp; 00034 } 00035 } 00036 00037 /* 00038 * Copy value of size bytes (use sizeof(type)) to buffer 00039 */ 00040 void toBytes(char *buffer, void *value, size_t size) 00041 { 00042 int i; 00043 00044 for (i = 0; i < size; i++) 00045 buffer[i] = *((char *) value + i); 00046 }
Generated on Mon Jul 18 2022 01:02:56 by
