DAY 040: _TOGGLEBIT
#1
Here is an interesting one for all you bit flipping coders out there...

_TOGGLEBIT

SYNTAX result = _TOGGLEBIT(numericalVariable, numericalValue)

Usage: For cross breeding elephants and rhinos. What's that good for? Eleph-i-no!

Okay, I know bit-flipping can be used somehow to detect a hardware malfunction in a Windows operating system. I would imagine encryption would be another practical use. I also did some reading on using bit-flipping as an alternative to doing string math, but that was a very involved process, so I have no work created to demonstrate how that would be accomplished.

What I can easily see if we flip the first bit, we can get a 0 or 1, which is good for a toggle function.

Now the easiest method to create your own toggle for a program has been demonstrated in this forum numerous times...

toggle = 1 - toggle Mark posted about that one months ago.

So using toggle = 1 - toggle we start out with toggle = 0, hence 1 - 0 = 1. Loop again and 1 - 1 = 0

Now we can accomplish the exact same toggle effect with _TOGGLEBIT, as follows...

Code: (Select All)
DIM a AS INTEGER ' Also avilable are _INTEGER64, LONG, _UNSIGNED, and _BYTE,
DO
    DO
        SELECT CASE a
            CASE 0
                PRINT " Steve is good...";
            CASE 1
                PRINT " Pete is better!": PRINT
        END SELECT
        SLEEP
        a = _TOGGLEBIT(a, 0)
        mykey$ = INKEY$
    LOOP UNTIL mykey$ = CHR$(9) OR mykey$ = CHR$(27)
    PRINT
    FOR i = 0 TO 15
        PRINT i; _TOGGLEBIT(a, i)
    NEXT
    PRINT
LOOP UNTIL mykey$ = CHR$(27)

So maybe this example will goad Steve a "bit" to elaborate on some of his experiences with _TOGGLEBIT. Also, I'd love to hear some comments from @jack about bit-flipping, and his experience with coding decfloat.

Pete
Reply


Messages In This Thread
DAY 040: _TOGGLEBIT - by Pete - 12-19-2022, 07:43 PM
RE: DAY 040: _TOGGLEBIT - by mnrvovrfc - 12-19-2022, 08:32 PM
RE: DAY 040: _TOGGLEBIT - by SMcNeill - 12-19-2022, 08:43 PM
RE: DAY 040: _TOGGLEBIT - by mnrvovrfc - 12-19-2022, 09:37 PM
RE: DAY 040: _TOGGLEBIT - by SMcNeill - 12-19-2022, 09:05 PM
RE: DAY 040: _TOGGLEBIT - by Pete - 12-19-2022, 09:17 PM
RE: DAY 040: _TOGGLEBIT - by SMcNeill - 12-19-2022, 09:47 PM
RE: DAY 040: _TOGGLEBIT - by Pete - 12-19-2022, 10:03 PM
RE: DAY 040: _TOGGLEBIT - by SMcNeill - 12-19-2022, 10:22 PM
RE: DAY 040: _TOGGLEBIT - by Pete - 12-19-2022, 10:30 PM
RE: DAY 040: _TOGGLEBIT - by SMcNeill - 12-19-2022, 10:42 PM
RE: DAY 040: _TOGGLEBIT - by bplus - 12-19-2022, 11:20 PM
RE: DAY 040: _TOGGLEBIT - by Pete - 12-19-2022, 11:22 PM
RE: DAY 040: _TOGGLEBIT - by Jack - 12-19-2022, 11:58 PM
RE: DAY 040: _TOGGLEBIT - by Pete - 12-20-2022, 01:11 AM
RE: DAY 040: _TOGGLEBIT - by vince - 12-20-2022, 01:59 AM
RE: DAY 040: _TOGGLEBIT - by OldMoses - 12-20-2022, 03:46 AM



Users browsing this thread: 7 Guest(s)