Implemented numbase string conversion symbols.
h3rald h3rald@h3rald.com
Sat, 07 Oct 2023 14:14:17 +0200
2 files changed,
37 insertions(+),
0 deletions(-)
M
minpkg/lib/min_str.nim
→
minpkg/lib/min_str.nim
@@ -293,6 +293,42 @@ let b = vals[0].getString
var s = a & b i.push s.newVal + def.symbol("to-hex") do (i: In): + let vals = i.expect("int") + let v = vals[0].intVal + i.push (v.toHex(sizeof(v)).newVal) + + def.symbol("to-oct") do (i: In): + let vals = i.expect("int") + let v = vals[0].intVal + i.push (v.toOct(sizeof(v)).newVal) + + def.symbol("to-dec") do (i: In): + let vals = i.expect("int") + let v = vals[0].intVal + i.push ($v).newVal + + def.symbol("to-bin") do (i: In): + let vals = i.expect("int") + let v = vals[0].intVal + i.push (v.toBin(sizeof(v)).newVal) + + def.symbol("from-hex") do (i: In): + let vals = i.expect("'sym") + i.push fromHex[BiggestInt](vals[0].getString).newVal + + def.symbol("from-oct") do (i: In): + let vals = i.expect("'sym") + i.push fromOct[BiggestInt](vals[0].getString).newVal + + def.symbol("from-bin") do (i: In): + let vals = i.expect("'sym") + i.push fromBin[BiggestInt](vals[0].getString).newVal + + def.symbol("from-dec") do (i: In): + let vals = i.expect("'sym") + i.push parseInt(vals[0].getString).newVal + def.symbol("%") do (i: In): i.pushSym("interpolate")
M
next-release.md
→
next-release.md
@@ -3,6 +3,7 @@
* Added support for binary (0b) octal (0o), and hexadecimal (0x) integers in parser. * Added `base` and `base?` symbols to set and get the current number base (dec, hex, bin or oct). * Added `bitand`, `bitor`, `bitxor`, `bitparity`, `bitreverse`, `bitclear`, `bitflip`, `bitset`, `bitmask` symbols for biwise operations. +* Added `to-(hex|bin|dec|oct)` and `from-(hex|bin|dec|oct)` symbols to convert integers to and from different string representations. ### Fixes and Improvements