[REBOL] Re: parse rule for converting hex to decimal
From: gregg:pointillistic at: 22-Feb-2010 18:08
Hi Semseddin,
SM> is there anyone already write a parse rule to convert hexadecimal to
SM> decimal? here is my situation,
Others have responded, so I'll just add this version for consderation.
Feel free to post any questions about the naming conventions or
structure.
-- Gregg
text: {$FA,$20,$33,$0102}
hex-digit=: charset "0123456798ABCDEF"
=hex-digits: none
hex-digits=: [copy =hex-digits some hex-digit=]
=hex-num: none
hex-num=: [#"$" hex-digits= actions/hex-num=]
actions: [
hex-num= (print hex-to-dec =hex-digits)
]
hex-to-dec: func [hex-digits [string!]] [
to integer! debase/base hex-digits 16
]
parse/all text [some [opt #"," hex-num=]]