diff options
Diffstat (limited to 'itoa_gen.py')
| -rw-r--r-- | itoa_gen.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/itoa_gen.py b/itoa_gen.py new file mode 100644 index 0000000..0437c62 --- /dev/null +++ b/itoa_gen.py @@ -0,0 +1,15 @@ +with open("itoa_lut.h", "w") as f: + f.write("#include <stdint.h>\n") + f.write("typedef union { struct { char chars[3]; uint8_t len; } fields; uint32_t bits; } LutEntry;\n") + f.write("const uint32_t itoa_lut[256] = {") + out = [] + for i in range(0, 256): + running=len(str(i)) + for j in reversed(range(3)): + running = running << 8 + if j < len(str(i)): + running += ord(str(i)[j]) + out.append(hex(running)) + f.write(", ".join(out)) + f.write("};") + |
