blob: b7a8a20959fbb7c651905e29cd23e38bae4ed630 (
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
30
31
32
33
34
35
36
|
/*
* itos16.cpp:
* written by palmers / teso
*/
#include <itos16.hpp>
#include <iostream>
string itos16 (unsigned int x)
{
char t[] = "0123456789abcdef";
string y;
unsigned int a,
base = 1,
z = 0;
while (base < x && z++ < 7)
base *= 16;
if (z != 8 && z != 0)
base /= 16;
while (base != 1)
{
a = 0;
while (x >= base)
{
a++;
x -= base;
}
y += t[a];
base /= 16;
}
y += t[x];
return y;
}
|