Forums Register Login

and and or operator help

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
Was this meant to be a reply to another topic?

Donald Gooden wrote:my question is when would i need to actually use the & ,| operators ?when will i need to manipulate the bits in a variable?


Yes. Which in my experience is a very rare occasion.
+Pie Number of slices to send: Send
no it was meant to be a new thread
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
I had to Google for myself, because the Ranch search seems to be misbehaving. I found this which will probably help you.
+Pie Number of slices to send: Send
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:
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Some basic illustration on the bitwise operators are as follows:

The & operator states that each bit in the values are compared where:
1 & 1 = 1
1 & 0 = 0
0 & 0 = 0


The | operator states that each bit in the values are compared where:
1 | 1 = 1
1 | 0 = 1
0 | 0 = 0


The ^ operator states that each bit in the values are compared where:
1 ^ 1 = 0
1 ^ 0 = 1
0 ^ 0 = 0
Good night. Drive safely. Here's a tiny ad for the road:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 533 times.
Similar Threads
problem with mask and bitwise manipulator
Dan's Question: Operators and Assignments
shift operators
bit operations
Confused with logic
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:22:56.