Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

parse rule for converting hex to decimal

 [1/20] from: semseddinm:bircom at: 22-Feb-2010 14:01


is there anyone already write a parse rule to convert hexadecimal to decimal? here is my situation, text: {$FA,$20,$33,$0102} result: copy [] rule: [(append value to result)] parse text rule result

 [2/20] from: brock:kalef:innovapost at: 22-Feb-2010 10:38


You should be able to get what you want with this code segment... print to-integer debase/base "fa" 16
>> 250

 [3/20] from: sqlab:gmx at: 22-Feb-2010 16:06


one of many solutions parse/all text [ (result: make block! 5) some [ thru "$" copy x to "," ( append result to-integer debase/base x 16) skip ] thru "$" copy x to end ( append result to-integer debase/base x 16) ] result On 22.02.2010 13:01, Åžemseddin Moldibi wrote:

 [4/20] from: Tom:Conlin:gmai:l at: 22-Feb-2010 6:15


sorry , no time to give a proper answer but to get you started parse/all text [some["$" copy h to "," ","(print to-integer debase/base h 16) ] ] 250 32 51 == false S,emseddin Moldibi wrote:

 [5/20] from: semseddinm:bircom at: 22-Feb-2010 19:11


thanks a lot. Mon, 22 Feb 2010 17:06:00 +0200 tarihinde sqlab <sqlab-gmx.net> þöyle yazmýþ:

 [6/20] from: luke:marmaladefoo at: 22-Feb-2010 17:39


this just uses a simple parse and some post-processing foreach item (parse/all text "$,") [ if (0 < length? item) [ append result to-integer debase/base item 16 ] ] On 22 Feb 2010, at 14:01, semseddinm-bircom.com wrote: To: rebolist-rebol.com Date sent: Mon, 22 Feb 2010 14:01:45 +0200 Subject: [REBOL] parse rule for converting hex to decimal Copies to: semseddin-gmail.com From: semseddinm-bircom.com Organization: Bircom Send reply to: rebolist-rebol.com is there anyone already write a parse rule to convert hexadecimal to decimal? here is my situation, text: {$FA,$20,$33,$0102} result: copy [] rule: [(append value to result)] parse text rule result
>> [250 32 51 258]
-- To unsubscribe from the list, just send an email to lists at rebol.com with unsubscribe as the subject. __________________________________________ Various gadgets widgets, links and chat http://www.marmaladefoo.com

 [7/20] from: gregg:pointillistic at: 22-Feb-2010 17:53


Hi Luke, LOE> if (0 < length? item) [ EMPTY? is a very handy function for this idiom. -- Gregg

 [8/20] 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=]]

 [9/20] from: compkarori:gmai:l at: 22-Feb-2010 18:16


Additional comment: The 'empty? test is also unnecessary as 'foreach already does that test. foreach item parse/all text "$," [ append result to-integer debase/base item 16 ] 2010/2/23 Gregg Irwin <gregg-pointillistic.com>:
> Hi Luke, > LOE> if (0 < length? item) [
<<quoted lines omitted: 3>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- Graham Chiu http://www.compkarori.co.nz:8090/ Synapse - the use from anywhere EMR.

 [10/20] from: gregg:pointillistic at: 22-Feb-2010 22:10


Hi Graham, GC> The 'empty? test is also unnecessary as 'foreach already does that test. GC> foreach item parse/all text "$," [ GC> append result to-integer debase/base item 16 GC> ] I think Luke was using it to handle the case where a field is empty. e.g. parse/all text "$," Without the test, you'll get entries for the empty fields. -- Gregg

 [11/20] from: compkarori:g:mail at: 23-Feb-2010 2:18


Hi Gregg In that case, if the data is potentially suspect I would suggest this instead foreach item exclude parse/all text "$," [ "" ] [ append result to-integer debase/base item 16 ] On Tue, Feb 23, 2010 at 6:10 PM, Gregg Irwin <gregg-pointillistic.com> wrote:
> Hi Graham, > GC> The 'empty? test is also unnecessary as 'foreach already does that test.
<<quoted lines omitted: 9>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- Graham Chiu http://www.compkarori.co.nz:8090/ Synapse - the use from anywhere EMR.

 [12/20] from: sqlab:gmx at: 23-Feb-2010 7:43


Just because I want to know the delay between sending and receiving the posts I add one more parse/all text [ (result: make block! 5) some [ thru "$" copy x [ to "," | to end] ( append result to-integer debase/base x 16) skip ] ]
>> now/utc
== 23-Feb-2010/6:43:35 On 22.02.2010 16:06, sqlab wrote:

 [13/20] from: tomc:cs:uoregon at: 23-Feb-2010 0:22


sqlab wrote:
> Just because I want to know the delay between sending and receiving the > posts I add one more > > >> now/utc > == 23-Feb-2010/6:43:35
my delay for receiving your message is ... Mon, 22 Feb 2010 22:44:49 -0800 (PST) 75 seconds. -- ... nice weather eh tomc-cs.uoregon.edu

 [14/20] from: gregg:pointillistic at: 23-Feb-2010 8:43


Hi Graham, GC> foreach item exclude parse/all text "$," [ "" ] [ GC> append result to-integer debase/base item 16 GC> ] I don't think that will work, unless you're guaranteed to have unique values in the source. EXCLUDE is a set operation, so you'll lose matching hex values. -- Gregg

 [15/20] from: compkarori:gmai:l at: 23-Feb-2010 14:21


Hi Gregg I didn't realize that a set implies a collection of unique items.
>> help exclude
USAGE: EXCLUDE set1 set2 /case /skip size DESCRIPTION: Return the first set less the second set. EXCLUDE is a native value. ARGUMENTS: set1 -- First data set (Type: series bitset) set2 -- Second data set (Type: series bitset) REFINEMENTS: /case -- Uses case-sensitive comparison. /skip -- Treat the series as records of fixed size size -- (Type: integer) On Wed, Feb 24, 2010 at 4:43 AM, Gregg Irwin <gregg-pointillistic.com> wrote:
> Hi Graham, > GC> foreach item exclude parse/all text "$," [ "" ] [
<<quoted lines omitted: 7>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- Graham Chiu http://www.compkarori.co.nz:8090/ Synapse - the use from anywhere EMR.

 [16/20] from: gregg:pointillistic at: 23-Feb-2010 12:40


Hi Graham, GC> I didn't realize that a set implies a collection of unique items. Yup. All the set ops work that way, though the doc strings don't make it explicit. If you think of them in terms of "sets" it makes sense. -- Gregg

 [17/20] from: tom:conlin:gm:ail at: 23-Feb-2010 11:57


in math, uniquenesses is the defining characteristic of sets that makes them so useful. Graham Chiu wrote:

 [18/20] from: compkarori:g:mail at: 23-Feb-2010 18:26


Perhaps we need a set! datatype then ... On Wed, Feb 24, 2010 at 8:57 AM, tomc <tom.conlin-gmail.com> wrote:
> in math, uniquenesses is the defining characteristic > of sets that makes them so useful.
<<quoted lines omitted: 49>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- Graham Chiu http://www.compkarori.co.nz:8090/ Synapse - the use from anywhere EMR.

 [19/20] from: semseddinm:bircom at: 24-Feb-2010 11:28


Hi, It is strange but if I put a trace on just before the parse/all line script gives an error, otherwise it prints just first value. trace on parse/all text [some [opt #"," hex-num]] Match: (print hex-to-dec hex-digits) Input: ,$20,$33,$0102222 ** Script Error: Trace: "Invalid argument:" (string) Trace: :arg1 (get-word) Invalid argument: scheme: console r: copy [] parse/all {$FA,$20,$33,$0102} [some ["$" copy h to "," "," (append r to-integer debase/base h 16)] ] probe r runs well, but the last value is missing. {$FA,$20,$33,$0102,} works. Anyway, I got the idea :) thanks for all the replies.
> Hi Semseddin, > SM> is there anyone already write a parse rule to convert hexadecimal to
<<quoted lines omitted: 16>>
> ] > parse/all text [some [opt #"," hex-num=]]
-- =DDyi =E7al=FD=FEmalar, =DEemseddin Moldibi

 [20/20] from: sqlab:gmx at: 24-Feb-2010 10:59


On 24.02.2010 10:28, Þemseddin Moldibi wrote:
> Hi, > It is strange but if I put a trace on just before the
<<quoted lines omitted: 11>>
> ] > probe r
This string you are parsing here does not include a comma as the last char, as your rule demands. just look at my two former examples.

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted