all repos — min @ 8e775b56ccb59769a46fca5dc1f99f8d0d7d9cdb

A small but practical concatenative programming language.

Implemented numbase string conversion symbols.
h3rald h3rald@h3rald.com
Sat, 07 Oct 2023 14:14:17 +0200
commit

8e775b56ccb59769a46fca5dc1f99f8d0d7d9cdb

parent

0ab90668a5850ebe292e222ed776b85c755576d6

2 files changed, 37 insertions(+), 0 deletions(-)

jump to
M minpkg/lib/min_str.nimminpkg/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.mdnext-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