1 /* -------------------------------- Arctic Core ------------------------------
\r
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\r
6 * This source code is free software; you can redistribute it and/or modify it
\r
7 * under the terms of the GNU General Public License version 2 as published by the
\r
8 * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
\r
10 * This program is distributed in the hope that it will be useful, but
\r
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
\r
14 * -------------------------------- Arctic Core ------------------------------*/
\r
17 * Itoa based on K&R itoa
\r
26 * Convert a number to a string
\r
28 * @param val The value to convert
\r
29 * @param str Pointer to a space where to put the string
\r
30 * @param base The base
\r
31 * @param negative If negative or not.
\r
33 void xtoa( unsigned long val, char* str, int base, int negative) {
\r
42 if( base < 10 && base > 16 ) {
\r
49 str[i++] = "0123456789abcdef"[ val % base ];
\r
50 } while ((val /= base) > 0);
\r
67 #if defined(TEST_XTOA)
\r
68 /* Some very limited testing */
\r
74 xtoa(-123,str,10,1);
\r
76 xtoa(0xa123,str,16,0);
\r
78 xtoa(-0xa123,str,16,1);
\r
88 * Converts an unsigned long to a string
\r
90 * @param value The value to convert
\r
91 * @param str Pointer to the string
\r
92 * @param base The base
\r
94 void ultoa(unsigned long value, char* str, int base) {
\r
95 xtoa(value, str, base, 0);
\r
99 * Converts an integer to a string
\r
101 * @param value The value to convert
\r
102 * @param str Pointer to the string to write to
\r
103 * @param base The base
\r
105 char * itoa(int value, char* str, int base) {
\r
106 xtoa(value, str, base, (value < 0));
\r