Oring two values..???

Matchu04

Lifetime Supporting Member
Join Date
Mar 2013
Location
Northampton
Posts
287
I was wondering if someone could explain why you would want to "or" two memory words together... I understandhow to do it but not understand why..?? I know by anding them you are truncating them (I believe this the correct word) but oring got me lost...??

Oring.jpg
 
Last edited:
You have to remember that the values are made up of a number of bits. The AND function between two values preserves those bits which are ON (1) in both of the values bit positions. The OR function preserves those bits which are ON (1) in either of the values bit positions.

Typically you would see these if the nubers are being used more for their bit position storage.

As you mention - truncating is indicated if an AND function is used and one of the values has bits ON in the upper positions allowing only those positions in the other value to pass to the destination. Another would be a MOD if an AND function is used and only the bottom bits are on in one of the values.
 
You have to remember that the values are made up of a number of
bits. The AND function between two values preserves those bits which are ON (1) in both of the values bit positions. The OR function preserves those bits which are ON (1) in either of the values bit positions.

This I understand...

Code:
       L     DBW   14
       L     2#10000000
       OW    
       T     [COLOR=black]DBW   14[/COLOR]

So in my example then the minimum value in DBW14 will be 10000000.. After the or that is
 
I aam not very familiar with this system so I can't be sure that I can interpret what is going on let alone guess why.

I did hazard a guess AS I noticed from when I read you other posts your an AB man...

All this code is doing is Oring DBW14 with 10000000 and transfering it back into DBW14
 
If the code is doing as you suggest, then it is turning ON bit #7 (bit #0 being rightmost). Actually it is ensuring that bit #7 is ON.

word 1 = 01000
word 2 = 00010
result = 01010

if the bit is on in one word OR the other then turn on the result bit...
 
If the code is doing as you suggest, then it is turning ON bit #7 (bit #0 being rightmost). Actually it is ensuring that bit #7 is ON.

word 1 = 01000
word 2 = 00010
result = 01010

if the bit is on in one word OR the other then turn on the result bit...

Yes... in my example 2#10000000 is in base 2 so 10000000
would be 128 as a INT. I kind of understood it just curious to know why but I think the penny has dropped...
 
I did hazard a guess AS I noticed from when I read you other posts your an AB man...

All this code is doing is Oring DBW14 with 10000000 and transfering it back into DBW14

I think the key to understanding the original intent, may lay in searching out what is being done with the individual bits as well as any compare logic looking for the result to match a certain value.

Since the result is being stored back into one of the operands, perhaps it is accumulating alarms states or axes has been homed? or waiting for a certain number of limit switches to "have been made" but in any order...just wags...
 
I was wondering if someone could explain why you would want to "or" two memory words together... I understandhow to do it but not understand why..?? I know by anding them you are truncating them (I believe this the correct word) but oring got me lost...??


By oring a word to a copy of what the word's value was on the previous iteration, it could be done as part of a masking scheme to detect bit transitions within a bit array, but an Exclusive OR would probably work best for that?

You could use an OR to monitor two words to detect if either of them has a bit high at a particular bit offset.

I've had occasions in which I've had legitimate uses for OR matrix functions, but it's been quite a while since I've had a reason to use one.
 
I just think of it as doing the same thing as a set --(s)-- of DB15.0. The OR just lets you set any bits in the entire word all at once so it can be much faster to use the OR if you have a bunch of bits to set at once.

For those folks that have written bit manipulation code in other languages like C, Java,... (that don't support single bit operations) they are used to performing single bit operations this way - so you'll likely run across the OR and the AND NOT (the way to clear bits) multiple times in your career.
 

Similar Topics

I cannot find anything that says that Topserver or any OPC server stores values. (except in the simulator or the Historian plug in). My...
Replies
6
Views
1,579
Hi. So I finally got my HSC to work with the RA_HSCPlugin thanks to @PLC Pie Guy . I'm using an AB 2080-LC20-20QWB with a 2080-MOT-HSC extension...
Replies
8
Views
1,828
Hello, During runtime I change values of some internal tags (i.e. F_CV of DO tags). And I want them to be saved when I switch runtime off, and...
Replies
10
Views
5,456
hello. i am trying to store the values of a sensor every 1 minute to an array of 3. and compare the 3 values to see of the values is increasing or...
Replies
12
Views
3,526
Hi guys. Just upgraded to 5000. Still getting my head around 500 but due to an upgrade of hardware new software needed. So after some...
Replies
4
Views
2,448
Back
Top Bottom