Aug 5, 2016 Replies: 3 ======================================= EDIT: I just got pwned by @GKCS, a = 1 - a. I guess I like to over complicate things... ========================================== Everyone knows how easy it is to switch a Boolean "on and off": Code: Copy myBool = (myBool == False) 'Uglier and faster than Not(myBool) ...but how about switching a Short or Int between 0 and 1? Code: Copy Dim a = 0 as Short 'Some loop If a = 0 Then a = 1 Else a = 0 'End of loop Not bad but can we do it in a single statement? Code: Copy Dim a = 0 As Short 'Some loop a = Bit.Xor(0x0001, a) '0x00000001 for Int 'End of loop Pretty awesome, huh? Last edited: Aug 7, 2016 Click to expand...
======================================= EDIT: I just got pwned by @GKCS, a = 1 - a. I guess I like to over complicate things... ========================================== Everyone knows how easy it is to switch a Boolean "on and off": Code: Copy myBool = (myBool == False) 'Uglier and faster than Not(myBool) ...but how about switching a Short or Int between 0 and 1? Code: Copy Dim a = 0 as Short 'Some loop If a = 0 Then a = 1 Else a = 0 'End of loop Not bad but can we do it in a single statement? Code: Copy Dim a = 0 As Short 'Some loop a = Bit.Xor(0x0001, a) '0x00000001 for Int 'End of loop Pretty awesome, huh?
wonder Expert Licensed User Longtime User Aug 5, 2016 #3 GKCS said: a=1-a Click to expand... Yeah, it works!! Touché, @GKCS!! Last edited: Aug 5, 2016
S sorex Expert Licensed User Longtime User Aug 5, 2016 #4 depending on the situation of having a general counter like in your loop example one could use Code: Copy for x=0 to 5 log(x mod 2) next or for x=0 to 5 log(bit.and(x,1) next
depending on the situation of having a general counter like in your loop example one could use Code: Copy for x=0 to 5 log(x mod 2) next or for x=0 to 5 log(bit.and(x,1) next