Subj : Re: MPL Bitwise Operators
To : g00r00
From : LEE WESTLAKE
Date : Thu Jan 13 2022 11:35 pm
g0> MPL is supposed to support your typical bitwise operators (keywords
g0> and/or/xor/shl/shr) but clearly something is not working.
I certainly miss them when they're not there, but an arithmetic solution
proved just as good.
g0> There are also three functions that allow you to check, set, and toggle
g0> bits in any integer type that MPL supports which can be used for now
g0> until I figure out what happened.
g0>
g0> This is in a WHATSNEW from way back in 2011 (The number you pass is the
g0> actual bit you want to check, set or toggle ie 1-32)
g0>
g0> + New MPL function "BitCheck" accepts a bit position and checks it
g0> against an integer, returning true or false if the bit is on. So for
g0> example in the Records, the third bit in UserFlags is UserDeleted:
g0>
g0> GetThisUser
g0> If BitCheck(3, UserFlags) Then WriteLn('User is marked deleted');
g0>
g0> Note that this was implemented before actual bitwise math, which also
g0> made it into this version. Keep reading! :)
g0>
g0> + New MPL function "BitToggle" accepts a bit position and an integer and
g0> toggles the bit.
g0>
g0> GetThisUser
g0> BitToggle(3, UserFlags); // undeletes if they are deleted or
g0> deletes if // they are not deleted.
g0>
g0> + New MPL function "BitSet" accepts a bit position and an integer and
g0> sets the bit ON/OFF based on a boolean:
g0>
g0> GetThisUser
g0> BitSet(3, UserFlags, True); // user is marked as deleted
Thanks g00r00, I appreciate the additional information.
o-----------o------------o-------------------------o
TALIADON | 2:250/6 | 21:3/138 |
[email protected] |
o-----------o-----------o------------o-------------------------o
| "Error is a great teacher, and humility its hardest lesson." |
o--------------------------------------------------------------o
--- Mystic BBS v1.12 A46 2020/08/26 (Windows/32)
* Origin: TALIADON BBS (2:250/6)