It is currently April 19th, 2024, 3:11 am

Questions About Calc Measure

Get help with creating, editing & fixing problems with skins
User avatar
Lssg97
Posts: 36
Joined: October 21st, 2018, 2:55 am

Questions About Calc Measure

Post by Lssg97 »

Hi everyone, I may need help.

I want to make a skin related to "Convert Digital Numeric". I researched the Calc Measure and found that it can participate in calculations with other types of bases, but it does not seem to support the direct output of results in other bases. Can the Calc Measure output string in other bases after calculation?
Last edited by Lssg97 on March 5th, 2020, 7:13 am, edited 1 time in total.
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Questions About Calc Measure

Post by mak_kawa »

Hi Lssg97

What do you mean "bases"? Logarithmic base? I am not sure. Can you elaborate what you want/try with sample skin code?
User avatar
Lssg97
Posts: 36
Joined: October 21st, 2018, 2:55 am

Re: Questions About Calc Measure

Post by Lssg97 »

mak_kawa wrote: March 5th, 2020, 4:13 am Hi Lssg97

What do you mean "bases"? Logarithmic base? I am not sure. Can you elaborate what you want/try with sample skin code?
Sorry, I may not have described it well. In a nutshell: I want to enter a decimal number and convert it to hexadecimal.
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Questions About Calc Measure

Post by mak_kawa »

The conversion is too difficult for me, honestly I can't... :-) Hope someone else in this forum helps you.
User avatar
Brian
Developer
Posts: 2678
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Questions About Calc Measure

Post by Brian »

One solution would be to use a Lua script using an inline section variable.
https://docs.rainmeter.net/manual/lua-scripting/inline-lua/

Script.lua

Code: Select all

-- You can use a number or string as input
function ToHex(num)
	return string.format("0x%X", tostring(num or 0))
end
Skin.ini

Code: Select all

[Lua]
Measure=Script
ScriptFile=Script.lua

[Output]
Meter=String
Text=[Lua:ToHex(10)]
DynamicVariables=1
It should output 0xA.

-Brian
User avatar
Lssg97
Posts: 36
Joined: October 21st, 2018, 2:55 am

Re: Questions About Calc Measure

Post by Lssg97 »

Brian wrote: March 5th, 2020, 6:51 am One solution would be to use a Lua script using an inline section variable.
https://docs.rainmeter.net/manual/lua-scripting/inline-lua/

Script.lua

Code: Select all

-- You can use a number or string as input
function ToHex(num)
	return string.format("0x%X", tostring(num or 0))
end
Skin.ini

Code: Select all

[Lua]
Measure=Script
ScriptFile=Script.lua

[Output]
Meter=String
Text=[Lua:ToHex(10)]
DynamicVariables=1
It should output 0xA.

-Brian
Thank! It got the results I wanted. And pleasantly surprised that it also supports two's complement representation.
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Questions About Calc Measure

Post by mak_kawa »

I have tried Dec-Hex conversion without Lua script/built-in function, only Calc measures!!...really awful coding.:-)

Code: Select all

[Rainmeter]
Update=1000
BackgroundMode=2
SolidColor=128,128,128,192

[Variables]
Source=2744
Result0=0
Result1=0
Result2=0
Result3=0
Result4=0

[measureCalc1]
Measure=Calc
Formula=Trunc(#Source#/16)
IfCondition=measureCalc1 = 0
IfTrueAction=[!SetVariable Result0 (#Source#%16)][!SetVariable Result1 ([measureCalc1]%16)]
IfFalseAction=[!SetVariable Result0 (#Source#%16)][!SetVariable Result1 ([measureCalc1]%16)][!EnableMeasure measureCalc2]
DynamicVariables=1

[measureCalc2]
Measure=Calc
Formula=Trunc([measureCalc1]/16)
IfCondition=[measureCalc2] = 0
IfTrueAction=[!SetVariable Result2 ([measureCalc2]%16)]
IfFalseAction=[!SetVariable Result2 ([measureCalc2]%16)][!EnableMeasure measureCalc3][!DisableMeasure measureCalc2]
DynamicVariables=1
Disabled=1

[measureCalc3]
Measure=Calc
Formula=Trunc([measureCalc2]/16)
IfCondition=measureCalc3 = 0
IfTrueAction=[!SetVariable Result3 ([measureCalc3]%16)]
IfFalseAction=[!SetVariable Result3 ([measureCalc3]%16)][!EnableMeasure measureCalc4][!DisableMeasure measureCalc3]
DynamicVariables=1
Disabled=1

[measureCalc4]
Measure=Calc
Formula=Trunc([measureCalc3])
IfCondition=measureCalc4 = 0
IfTrueAction=[!SetVariable Result4 ([measureCalc4]%16)]
IfFalseAction=[!SetVariable Result4 ([measureCalc4]%16)][!DisableMeasure measureCalc4]
DynamicVariables=1
Disabled=1

[ResultConvert]
Measure=String
String=#Result4##Result3##Result2##Result1##Result0#
Substitute="15":"F","14":"E","13":"D","12":"C","11":"B","10":"A","0":""
DynamicVariables=1

[meterResult]
Meter=String
X=5
Y=5
W=150
H=30
Text=Decimal: #Source##CRLF#Hexadecimal: 0x[ResultConvert]
DynamicVariables=1
This code converts "2744" decimal digits to "AB8" hexadecimal.
Untitled-1.png
You do not have the required permissions to view the files attached to this post.
User avatar
Lssg97
Posts: 36
Joined: October 21st, 2018, 2:55 am

Re: Questions About Calc Measure

Post by Lssg97 »

mak_kawa wrote: March 5th, 2020, 7:13 am I have tried Dec-Hex conversion without Lua script/built-in function, only Calc measures!!...really awful coding.:-)

Code: Select all

[Rainmeter]
Update=1000
BackgroundMode=2
SolidColor=128,128,128,192

[Variables]
Source=2744
Result0=0
Result1=0
Result2=0
Result3=0
Result4=0

[measureCalc1]
Measure=Calc
Formula=Trunc(#Source#/16)
IfCondition=measureCalc1 = 0
IfTrueAction=[!SetVariable Result0 (#Source#%16)][!SetVariable Result1 ([measureCalc1]%16)]
IfFalseAction=[!SetVariable Result0 (#Source#%16)][!SetVariable Result1 ([measureCalc1]%16)][!EnableMeasure measureCalc2]
DynamicVariables=1

[measureCalc2]
Measure=Calc
Formula=Trunc([measureCalc1]/16)
IfCondition=[measureCalc2] = 0
IfTrueAction=[!SetVariable Result2 ([measureCalc2]%16)]
IfFalseAction=[!SetVariable Result2 ([measureCalc2]%16)][!EnableMeasure measureCalc3][!DisableMeasure measureCalc2]
DynamicVariables=1
Disabled=1

[measureCalc3]
Measure=Calc
Formula=Trunc([measureCalc2]/16)
IfCondition=measureCalc3 = 0
IfTrueAction=[!SetVariable Result3 ([measureCalc3]%16)]
IfFalseAction=[!SetVariable Result3 ([measureCalc3]%16)][!EnableMeasure measureCalc4][!DisableMeasure measureCalc3]
DynamicVariables=1
Disabled=1

[measureCalc4]
Measure=Calc
Formula=Trunc([measureCalc3])
IfCondition=measureCalc4 = 0
IfTrueAction=[!SetVariable Result4 ([measureCalc4]%16)]
IfFalseAction=[!SetVariable Result4 ([measureCalc4]%16)][!DisableMeasure measureCalc4]
DynamicVariables=1
Disabled=1

[ResultConvert]
Measure=String
String=#Result4##Result3##Result2##Result1##Result0#
Substitute="15":"F","14":"E","13":"D","12":"C","11":"B","10":"A","0":""
DynamicVariables=1

[meterResult]
Meter=String
X=5
Y=5
W=150
H=30
Text=Decimal: #Source##CRLF#Hexadecimal: 0x[ResultConvert]
DynamicVariables=1
This code converts "2744" decimal digits to "AB8" hexadecimal.

Untitled-1.png
Thank you for your help. My original idea was similar to yours, but it is really difficult to express negative numbers.
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Questions About Calc Measure

Post by mak_kawa »

Ah...negative numbers...I didn't consider about it at all. :-)
User avatar
Yincognito
Rainmeter Sage
Posts: 7125
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Questions About Calc Measure

Post by Yincognito »

mak_kawa wrote: March 5th, 2020, 7:13 amI have tried Dec-Hex conversion without Lua script/built-in function, only Calc measures!!...really awful coding.:-)
Here's a shorter (and hopefully, better) coding. It works for conversions of up to base 35 ... simply because I wasn't sure of the letter-like notation for "digits" greater than 35 (i.e. Z).

Code: Select all

[Variables]
Number=2744
Quotient=(#Number#)
Result=""
Base=20

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

---Measures---

[MeasureConvert]
Measure=Calc
Formula=(#Quotient#%#Base#)
UpdateDivider=-1
RegExpSubstitute=1
Substitute="^10$":"A","^11$":"B","^12$":"C","^13$":"D","^14$":"E","^15$":"F","^16$":"G","^17$":"H","^18$":"I","^19$":"J","^20$":"K","^21$":"L","^22$":"M","^23$":"N","^24$":"O","^25$":"P","^26$":"Q","^27$":"R","^28$":"S","^29$":"T","^30$":"U","^31$":"V","^32$":"W","^33$":"X","^34$":"Y","^35$":"Z"
IfCondition=((#Quotient#)<>0)
IfTrueAction=[!SetVariable Result "[MeasureConvert]#Result#"][!SetVariable Quotient (Trunc(#Quotient#/#Base#))][!UpdateMeasure "MeasureConvert"]
IfConditionMode=1
DynamicVariables=1

---Meter---

[MeterConvert]
Meter=STRING
X=5
Y=5
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
Text="Number = #Number##CRLF#Base   = #Base##CRLF#Result = #Result#"
DynamicVariables=1
No need or multiple Calc measures, one is enough if updated properly after a conversion step, and the addition of "digits" to the string is done "backwards". Naturally, the base can be changed.
Lssg97 wrote: March 5th, 2020, 7:16 amThank you for your help. My original idea was similar to yours, but it is really difficult to express negative numbers.
So how does one convert negative numbers to base N? As far as I understood, there is the extension of two's complement for conversion to binary, but what about other bases? Just curious...
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth