im trying to understand what ivor is saying about the and, and or operators and the mask.
if i understand it correctly the & operator prevents you from changing a bit that is one when a mask is involved and changes all others to 0
and the | operator forces a bit to 1 when the mask is 1.
my question is when would i need to actually use the & ,| operators ?when will i need to manipulate the bits in a variable?
You should have said Ivor is the author of the book you are using, otherwise who will know?
Find out the constants in the Font class which mean bold, italic, etc. You may find they are powers of 2, like 1 2 4 8 etc. That means they have one 1 bit and 31 0 bits. That means you can use the bitwise or operator to put the two together, so 2 | 1 will have two bits set, making 3. If the bit has already been set in the font attributes, repeated use of the or operator won't change it.
You can toggle a bit with the exclusive or operator.
You can find whether a bit has been set with the and operator
The only cases I've used them were when I was working with file formats or protocols or hardware, where data is put in as tiny a package as possible.
A concrete example is that I made an editor for an old game I enjoyed. Characters could move around in areas. These areas had a couple of binary properties, for instance, whether they were indoor or outdoor, whether it could rain/snow or not, and a few others. You only need a bit of information to store each particular property, but most machines can't work with anything smaller than a byte.
To add the properties, you can use the | operator:
To check or remove properties, you can use the & operator:
i thought i stated it was ivors book my apologies my hands seemed to move slower then my brain
are you saying the fonts have one 1bit and 31 0's ? and the & and | operator can be used to manipulate these bits?
im trying to get a firm grasp on the arithmetic operators
a better understanding of
floating point arithmetic
op= operators
and the cast and explicit cast any suggestions or explanations from the community would be grateful.