Changeset 6e716a59 in mainline for generic/src/lib/func.c
- Timestamp:
- 2005-12-10T15:05:46Z (20 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 72f5866d
- Parents:
- a3ac9a7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
generic/src/lib/func.c
ra3ac9a7 r6e716a59 114 114 } 115 115 } 116 117 /** Convert ascii representation to __native 118 * 119 * Supports 0x for hexa & 0 for octal notation. 120 * Does not check for overflows, does not support negative numbers 121 * 122 * @param text Textual representation of number 123 * @return Converted number or 0 if no valid number ofund 124 */ 125 __native atoi(const char *text) 126 { 127 int base = 10; 128 __native result = 0; 129 130 if (text[0] == '0' && text[1] == 'x') { 131 base = 16; 132 text += 2; 133 } else if (text[0] == '0') 134 base = 8; 135 136 while (*text) { 137 result *= base; 138 if (base != 16 && *text >= 'A' && *text <= 'F') 139 break; 140 if (base == 8 && *text >='8') 141 break; 142 143 if (*text >= '0' && *text <= '9') 144 result += *text - '0'; 145 else if (*text >= 'A' && *text <= 'F') 146 result += *text - 'A' + 10; 147 else 148 break; 149 text++; 150 } 151 152 return result; 153 }
Note:
See TracChangeset
for help on using the changeset viewer.