diff options
Diffstat (limited to 'other/Kermit/lib/stoi16.cpp')
| -rw-r--r-- | other/Kermit/lib/stoi16.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/other/Kermit/lib/stoi16.cpp b/other/Kermit/lib/stoi16.cpp new file mode 100644 index 0000000..83aad59 --- /dev/null +++ b/other/Kermit/lib/stoi16.cpp | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | /* | ||
| 2 | * stoi16.cpp: | ||
| 3 | * written by palmers / teso | ||
| 4 | */ | ||
| 5 | #include <stoi16.hpp> | ||
| 6 | |||
| 7 | unsigned int stoi16 (string x) | ||
| 8 | { | ||
| 9 | int num = 0, | ||
| 10 | base = 1, | ||
| 11 | z = x.length () - 1; | ||
| 12 | unsigned int y = 0; | ||
| 13 | |||
| 14 | while (z >= 0) | ||
| 15 | { | ||
| 16 | if (x[z] <= '9' && x[z] >= '0') | ||
| 17 | num = x[z] - '0'; | ||
| 18 | if (x[z] <= 'f' && x[z] >= 'a') | ||
| 19 | num = x[z] - 'a' + 10; | ||
| 20 | if (x[z] <= 'F' && x[z] >= 'A') | ||
| 21 | num = x[z] - 'A' + 10; | ||
| 22 | |||
| 23 | y += num * base; | ||
| 24 | base *= 16; | ||
| 25 | z--; | ||
| 26 | } | ||
| 27 | return y; | ||
| 28 | } | ||
| 29 | |||
