[Idea/Request] Bit Mask Object
Thought this object could be quite handy, and reasonably simple to develop. A similar one already existed for MMF1.5:
A Bit Object for handling individual bits in a value (I think it was called the Bit Mask Object).
It would have the following features:
Bit Masking
Taking a value, and changing its bits using a masking string. EG:
changeBits("BMO", 32, "110--t--")
BMO is the name of the object.
This would take the value '32' (00100000) and convert it using the bit mask "110--t--"
In the mask, the possible characters are:
0 = force this bit to '0'
1 = force this bit to '1'
t = toggle this bit. So 1 becomes 0 and 0 becomes 1.
- = leave this bit as it is.
So the result would be 11000100 (196).
It could be useful for storing flags in objects that may not inherently handle flags, since it's just one number. You could also pass traits on to other objects easily. For example, suppose you had a game where an object has a series of flags, and when it shoots another object, the flags it has are passed on to its opponent. This could be done by copying just one value, instead of loads of individual flags.
You could also organise flags in alterable values, thereby giving them names. So a set of flags named 'Conversations' and 'Inventory data' and 'Level Settings' etc.
It could have a few settings that could be altered at runtime, such as:
- Left/Right aligned (e.g. if we have a 32 bit '0' and we have a mask of '011' (only 3 digits), LEFT align gives '01100000' and RIGHT align gives '00000011')
- Reverse value (e.g. a value like 217 (11011001) would become 155 (10011011). Literally the bits go from abcdefgh to hgfedcba)
It could potentially have a slightly more complex markup like this if people thought it might be useful, by adding a few more characters:
' = start a statement
* = repeat the statement to the end
eg:
1* = 11111111 (1 repeated in all further bits)
'10* = 10101010 (10 repeated in all further bits)
111'10* = 11110101 (111, then 10 repeated afterwards)
10*101 = 10101101 (10 repeated until the last three digits, which are 101)
Can't think of a use for the additional statements above, but the rest would be very handy.
Bit Blending with Mask
This would allow two values to be blended with a mask, e.g.
bitblend("BMO", 255, 217, "aox01fL0")
a = ADD
o = OR
x = XOR
0 = always a 0
1 = always a 1
f = the bit from the FIRST value
L = the bit from the LAST value
Re: [Idea/Request] Bit Mask Object
Here you go: http://people.pwf.cam.ac.uk/jlnw3/mmf/BitMask.zip
I didn't add the repeating character things as this was only a quick thing. The left/right align isn't done either (I prefer to think of it as all right-to-left, even though that isn't how it is stored in memory)
Feedback/Bugs/Better icon appreciated.
Re: [Idea/Request] Bit Mask Object
WOW, thanks! :)
You could possibly add a 'get number of bits' expression, for use with Get Nth Bit.
So '6' (110) would return a bit length of 3.
I'll try and make an icon for you.
Re: [Idea/Request] Bit Mask Object
Would this really be so useful? There are always 32 bits. This would just let you know which the bit is the last 'on' bit. Well I'll add it sometime if you like. It is just ceil(log[x]/log[2]).
I really need an icon for this!
Edit: Just saw your edit, thanks!
Re: [Idea/Request] Bit Mask Object
Lol, yeah, i hit Submit instead of preview! The ceil thing isn't too useful, just so you can choose not to have padded zeros if you wanna read only the relevant bits. It would be nice to have a little checkbox to toggle the endianness, cos I mostly work with the HO bit first (i forget if that's big endian or little endian), but this is lovely, thankyou!:D
I'll do an icon when I can, gotta sleep now:)
Re: [Idea/Request] Bit Mask Object
I hope this is an incentive to keep you in one place ;)
Re: [Idea/Request] Bit Mask Object
Re: [Idea/Request] Bit Mask Object
http://clickteam.info/neatwares/stuff/LIJI/BitMask.bmp
256 Colors BMP for VC++. :)
Re: [Idea/Request] Bit Mask Object
Cool thanks LIJI. I've updated it, added some docs and included the source code. Download here: http://people.pwf.cam.ac.uk/jlnw3/mmf2/mmf2.htm
Re: [Idea/Request] Bit Mask Object
Quote:
Originally Posted by Jax
I haven't made any worthwhile MMF2 extensions yet
You liar! :D ;)