1 /*******************************************************************
2 Components for embedded applications builded for
3 laboratory and medical instruments firmware
5 cmd_i2str.c - formated text to string conversion
6 without need to pull in whole stdio support
8 Copyright (C) 2001-2010 by Pavel Pisa pisa@cmp.felk.cvut.cz
9 (C) 2002-2010 by PiKRON Ltd. http://www.pikron.com
10 (C) 2007 by Michal Sojka <sojkam1@fel.cvut.cz>
12 This file can be used and copied according to next
14 - MPL - Mozilla Public License
15 - GPL - GNU Public License
16 - other license provided by project originators
17 *******************************************************************/
22 * Converts integer to string.
23 * @param s Buffer to store the result.
24 * @param val Value to convert.
25 * @param len Minimal width of the converted strign (padded by ' ').
26 * @param form Base of the number.
29 int i2str(char *s,long val,int len,int form)
34 unsigned base=form&0xff;
39 if((sig=(val<0)&&(base==10))) num=-val;
47 if(mag>(unsigned long)(~(unsigned long)0)/base) break;
58 if(form&I2STR_PAD_0) {
74 if(u>9) *(s++)='A'-10+u;