hart2hart Posted July 15 Posted July 15 (edited) Is there a way to use the binary variable functions to And, Or, or Xor your way to the absolute value of a variable without using an If to determine if - or + before doing bit manipulation? Edited July 15 by hart2hart Quote
larryllix Posted July 16 Posted July 16 10 hours ago, hart2hart said: Is there a way to use the binary variable functions to And, Or, or Xor your way to the absolute value of a variable without using an If to determine if - or + before doing bit manipulation? Repeat while var<0 var *= -1 Repeat 1 times ..... Quote
larryllix Posted July 16 Posted July 16 (edited) I cannot remember the exact logic but IIRC you XOR a number with 11111111111b or FFFFFFF and then add 1 ...but you still need a test to see if it needs it or you will make a positive variable negative. Edited July 16 by larryllix Quote
hart2hart Posted July 16 Author Posted July 16 I cannot remember the exact logic but IIRC you XOR a number with 11111111111b or FFFFFFF and then add 1 ...but you still need a test to see if it needs it or you will make a positive variable negative.Thanks. XOR and then +1 as negatives are stored as two’s complements is what I recalled but it does require an If to determine if negative. I think what I vaguely remember was some operand in assembly language on a VAX. It was do something and branch if in one instruction. Now that I think about it, it was macro-assembler so it was likely implemented in multiple machine language instructions. At least after the move from CISC to RISC processors. I just created another program so I could determine if negative and multiply by -1. Quote
larryllix Posted July 16 Posted July 16 4 hours ago, hart2hart said: Thanks. XOR and then +1 as negatives are stored as two’s complements is what I recalled but it does require an If to determine if negative. I think what I vaguely remember was some operand in assembly language on a VAX. It was do something and branch if in one instruction. Now that I think about it, it was macro-assembler so it was likely implemented in multiple machine language instructions. At least after the move from CISC to RISC processors. I just created another program so I could determine if negative and multiply by -1. See my inline method in the post above. Quote
hart2hart Posted July 16 Author Posted July 16 Repeat while var<0 var *= -1 Repeat 1 times ..... Thanks. I missed Repeat While being released in V5 FW likely because I didn't move over quickly. I looked Repeat While up the cookbook and it appears there is no construct like brackets to say what is included in the repeated loop. From your example the work around is to include another Repeat 1 times that ends the loop. In my case, if the repeat will be inline with additional statements before and after loop, then having the Repat 1 times will just execute those after normally -- correct? difference = 0 difference += some value difference -= another value Repeat while difference <0 Difference *= -1 Repeat 1 times Run Program 'some program' If Run Program 'another program' If I'll try it out this evening but thanks for bringing to my attention! 1 Quote
larryllix Posted July 16 Posted July 16 9 minutes ago, hart2hart said: Thanks. I missed Repeat While being released in V5 FW likely because I didn't move over quickly. I looked Repeat While up the cookbook and it appears there is no construct like brackets to say what is included in the repeated loop. From your example the work around is to include another Repeat 1 times that ends the loop. In my case, if the repeat will be inline with additional statements before and after loop, then having the Repat 1 times will just execute those after normally -- correct? difference = 0 difference += some value difference -= another value Repeat while difference <0 Difference *= -1 Repeat 1 times Run Program 'some program' If Run Program 'another program' If I'll try it out this evening but thanks for bringing to my attention! Correct. BTW: I feel the "Repeat 1 times" construct is an incorrect syntax as "Repeat 1 times" should mean to do the enclosed line twice (the first time and then the 1 repeat) , NOT a total of once as the repeat parameter number indicates. "Do 1 times" would have been more syntactically correct. 1 Quote
hart2hart Posted July 17 Author Posted July 17 Works great. Thanks. I’ve usually got a background project for cold winter days to clean stuff up so I’ll add this to list to look for. I’m curious what happens if someone creates an infinite loop. Does it run until reboot or is eISY looking for it? Quote
carealtor Posted July 17 Posted July 17 On 7/16/2024 at 5:45 AM, larryllix said: "Do 1 times" would have been more syntactically correct. "Repeat 0 times" ? Quote
larryllix Posted July 18 Posted July 18 11 hours ago, carealtor said: "Repeat 0 times" ? That used to not function at all. Quote
larryllix Posted July 18 Posted July 18 13 hours ago, hart2hart said: Works great. Thanks. I’ve usually got a background project for cold winter days to clean stuff up so I’ll add this to list to look for. I’m curious what happens if someone creates an infinite loop. Does it run until reboot or is eISY looking for it? Yes, many programs use infinite looping to create timed counters and cycle furnace fans and humidifiers etc... It will run until a power down or interrupted somehow, usually a human editing the program. Many schemes to restart these infinite loops have been used for power up conditions. Quote
carealtor Posted July 20 Posted July 20 On 7/17/2024 at 6:54 PM, larryllix said: That used to not function at all. Ah. Obviously I never tried it. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.