diff options
| author | Root THC | 2026-02-24 12:42:47 +0000 |
|---|---|---|
| committer | Root THC | 2026-02-24 12:42:47 +0000 |
| commit | c9cbeced5b3f2bdd7407e29c0811e65954132540 (patch) | |
| tree | aefc355416b561111819de159ccbd86c3004cf88 /other/Kermit/lib/itos16.cpp | |
| parent | 073fe4bf9fca6bf40cef2886d75df832ef4b6fca (diff) | |
initial
Diffstat (limited to 'other/Kermit/lib/itos16.cpp')
| -rw-r--r-- | other/Kermit/lib/itos16.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/other/Kermit/lib/itos16.cpp b/other/Kermit/lib/itos16.cpp new file mode 100644 index 0000000..b7a8a20 --- /dev/null +++ b/other/Kermit/lib/itos16.cpp | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | /* | ||
| 2 | * itos16.cpp: | ||
| 3 | * written by palmers / teso | ||
| 4 | */ | ||
| 5 | #include <itos16.hpp> | ||
| 6 | #include <iostream> | ||
| 7 | |||
| 8 | string itos16 (unsigned int x) | ||
| 9 | { | ||
| 10 | char t[] = "0123456789abcdef"; | ||
| 11 | string y; | ||
| 12 | unsigned int a, | ||
| 13 | base = 1, | ||
| 14 | z = 0; | ||
| 15 | |||
| 16 | while (base < x && z++ < 7) | ||
| 17 | base *= 16; | ||
| 18 | |||
| 19 | if (z != 8 && z != 0) | ||
| 20 | base /= 16; | ||
| 21 | |||
| 22 | while (base != 1) | ||
| 23 | { | ||
| 24 | a = 0; | ||
| 25 | while (x >= base) | ||
| 26 | { | ||
| 27 | a++; | ||
| 28 | x -= base; | ||
| 29 | } | ||
| 30 | y += t[a]; | ||
| 31 | base /= 16; | ||
| 32 | } | ||
| 33 | y += t[x]; | ||
| 34 | return y; | ||
| 35 | } | ||
| 36 | |||
