Mark,

I thought you would do this so well, and yes the power operator, I was 
about to ask for it.

Attached I have turned it into a macro that has different ways to pass the 
values and examples, needs pre-release 5.1.23.

I hope I am not too heavy "standing on your shoulders"?

Tones

On Saturday, 5 December 2020 at 12:37:24 UTC+11 Mark S. wrote:

> I was about to explain that the reduce operator wouldn't help because we 
> don't have a power operator when I thought to check ... and we do!
>
> So, great idea! And now we can forget recursive! 
>
> <$vars myhex="FFFF">
> <$vars 
> myfilter="[[16]power<index>]=[<currentTiddler>search-replace:g[A],[10]search-replace:g[B],[11]search-replace:g[C],[12]search-replace:g[D],[13]search-replace:g[E],[14]search-replace:g[F],[15]]+[product[]add<accumulator>]"
>  
> >
> <$list filter="[<myhex>split[]reverse[]reduce<myfilter>]" />
> </$vars>
> </$vars>
>
>
> On Friday, December 4, 2020 at 3:53:06 PM UTC-8 TW Tones wrote:
>
>> Mark et all,
>>
>> I think the new reduce operator may simplify this with each byte being 
>> converted at a time, making use of the accumulator and index.
>>
>> Regards
>> 'Tones
>>
>> On Thursday, 3 December 2020 at 17:46:07 UTC+11 TW Tones wrote:
>>
>>> Mark,
>>>
>>> I have followed your code through, More testing but it seems to all make 
>>> sense to me now, It would be great if we could turn such code into a 
>>> hierarchy chart that also recognised the list re-iterations. The 
>>> information is all there so automation would be possible. In this case I 
>>> can use the decimals in the range operator to satisfy the OT.
>>>
>>> Thank you
>>>
>>> Regards
>>> Tones
>>>
>>> On Thursday, 3 December 2020 at 17:05:17 UTC+11 TW Tones wrote:
>>>
>>>> Testing,
>>>>
>>>> Nice work, It takes a bit to follow the code, but I am sure I will 
>>>> learn something, thanks so much.
>>>>
>>>> You may see it in a Unicode database soon.
>>>>
>>>> Tones
>>>>
>>>>
>>>> On Thursday, 3 December 2020 at 16:53:47 UTC+11 Mark S. wrote:
>>>>
>>>>> Here's a recursive version that that can be any length of hex. Lightly 
>>>>> tested. Hopefully it's working OK.
>>>>>
>>>>> \define hex2dec2(byte,mult:1)
>>>>> <$vars 
>>>>> myfilter="[search-replace:g[A],[10]search-replace:g[B],[11]search-replace:g[C],[12]search-replace:g[D],[13]search-replace:g[E],[14]search-replace:g[F],[15]]">
>>>>> <$list filter="
>>>>> [<__byte__>subfilter<myfilter>] 
>>>>> =[<__mult__>]
>>>>> +[product[]]
>>>>> "/>
>>>>> </$vars>
>>>>> \end
>>>>> \define hex2dec-r(hex,mult)
>>>>> <$list filter="[<__mult__>] =16 +[product[]]" variable="mult">
>>>>> <$list filter="[<__hex__>split[]nth[1]]" variable="byte">
>>>>> <$list filter="[<__hex__>split[]rest[]join[]]" variable="hex"
>>>>> emptyMessage="<$macrocall $name=hex2dec2 byte=<<__hex__>> 
>>>>> mult=<<__mult__>> />"
>>>>> >
>>>>> <$macrocall $name=hex2dec2 byte=<<byte>> mult=<<__mult__>> />
>>>>> <$macrocall $name="hex2dec-r" hex=<<hex>> mult=<<mult>> />
>>>>> </$list></$list></$list>
>>>>> \end
>>>>> \define hex2dec-setup(hex)
>>>>> <$list filter="[<__hex__>split[]reverse[]join[]]" variable=rhex>
>>>>> <$macrocall $name=hex2dec-r hex=<<rhex>> mult=1 />
>>>>> </$list>
>>>>> \end
>>>>> \define hex2dec(hex)
>>>>> <$wikify text="<<hex2dec-setup $hex$>>" name=dec>
>>>>> <$list filter="[enlist<dec>sum[]]"/>
>>>>> </$wikify>
>>>>> \end
>>>>>
>>>>> <<hex2dec F111>>
>>>>>
>>>>>
>>>>>
>>>>> On Wednesday, December 2, 2020 at 5:42:55 PM UTC-8 TW Tones wrote:
>>>>>
>>>>>> Mark,
>>>>>>
>>>>>> Good start. I was thinking how to get 16^0 16^1 16^2 and 16^3 and you 
>>>>>> have hard coded it. If moving to a recursive process we may be able to 
>>>>>> handle variable length hex.
>>>>>>
>>>>>>>
>>>>>>>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/6f3889e0-155e-4f07-b752-9ecdcf48aeb3n%40googlegroups.com.

Attachment: Hexadecimal to Decimal macro and examples.json
Description: application/json

Reply via email to