summaryrefslogtreecommitdiff
path: root/other/Kermit/lib/stoi16.cpp
blob: 83aad59c080804d8126c5dc35b3f6502cad37396 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
 * stoi16.cpp:
 * written by palmers / teso
 */
#include <stoi16.hpp>

  unsigned int stoi16 (string x)
  {
    int			num = 0,
			base = 1,
			z = x.length () - 1;
    unsigned int	y = 0;

    while (z >= 0)
      {
        if (x[z] <= '9' && x[z] >= '0')
          num = x[z] - '0';
        if (x[z] <= 'f' && x[z] >= 'a')
          num = x[z] - 'a' + 10;
        if (x[z] <= 'F' && x[z] >= 'A')
          num = x[z] - 'A' + 10;

        y += num * base;
        base *= 16;
        z--;
      }
    return y;
  }