Geeks -Exclusive Or function XOR
#1
10K+ Poster!!
Thread Starter
iTrader: (1)
Join Date: May 2003
Location: Lancashire
Posts: 12,748
Likes: 0
Received 0 Likes
on
0 Posts
![Default](https://passionford.com/forum/images/icons/icon1.gif)
Ok,
Say I have 2 values. What does effect would an Exclusive OR function have on these 2 values? What would the output be?
Just got something I am trying to understand.
I understand that an OR function can have 2 inputs and either of the inputs being "on" will trigger an output and that an Exclusive OR means one or the other but not both will trigger an output, but I'm not sure how this would apply when talking values opposed to input signals.
Anybody care to comment?
Say I have 2 values. What does effect would an Exclusive OR function have on these 2 values? What would the output be?
Just got something I am trying to understand.
I understand that an OR function can have 2 inputs and either of the inputs being "on" will trigger an output and that an Exclusive OR means one or the other but not both will trigger an output, but I'm not sure how this would apply when talking values opposed to input signals.
Anybody care to comment?
#6
10K+ Poster!!
Thread Starter
iTrader: (1)
Join Date: May 2003
Location: Lancashire
Posts: 12,748
Likes: 0
Received 0 Likes
on
0 Posts
![Default](https://passionford.com/forum/images/icons/icon1.gif)
Ok, so if I had an input figure of 3642 and another of 1532, what would the outcome be?
I have a section of ladder logic running some XOR functions on 4 and 5 digit numbers and I'm trying to work out how it's doing the calculations.
I have a section of ladder logic running some XOR functions on 4 and 5 digit numbers and I'm trying to work out how it's doing the calculations.
Trending Topics
#10
Too many posts.. I need a life!!
Join Date: Nov 2008
Location: Notts
Posts: 549
Likes: 0
Received 0 Likes
on
0 Posts
![Default](https://passionford.com/forum/images/icons/icon1.gif)
What software are you using? Rockwell, Siemens, Schneider? There is usually some good help files on function blocks, I wouldn't imagine an XOR block to be very complicated, although I don't really understand the problem...
![Confused](https://passionford.com/forum/images/smilies/icon_confused.gif)
#11
![Default](https://passionford.com/forum/images/icons/icon1.gif)
![Confused](https://passionford.com/forum/images/smilies/icon_confused.gif)
So taking the hex string [87 A5 03 00 40 00 A7 03 30 00 00 B0 01 10 B4 03 00 01 00 A4 02 00 01], we'd start with hex "87". Since there is no bit before it, according to the CSAFE protocol we would XOR with hex "00", which basically just gives you hex "87" as the result again.
hex 00 = binary 00000000
hex 87 = binary 10000111
An XOR takes each binary bit value in the 1st binary string and compares it to the corresponding binary bit value in the 2nd binary string. If the values match (1 and 1, or 0 and 0) then the XOR of the bits would be a 0. If the values don't match (ie. 1 and 0, or 0 and 1) then the XOR of the bits would be 1.
So in the values above, XOR of the two binary strings would be as follows:
(hex 00 bit) ^ (corresponding hex 87 bit)
0 ^ 1 = 1
0 ^ 0 = 0
0 ^ 0 = 0
0 ^ 0 = 0
0 ^ 0 = 0
0 ^ 1 = 1
0 ^ 1 = 1
0 ^ 1 = 1
So the final XOR of the hex byte 00 and hex byte 87 would be binary 10000111 (which is also hex 87).
Next, we'd move onto comparing the previous result (ie. binary 10000111) with the next hex byte "A5"
hex 87 = binary 10000111 hex A5 = binary 10100101
(hex 87 bit) ^ (corresponding hex A5 bit)
1 ^ 1 = 0
0 ^ 0 = 0
0 ^ 1 = 1
0 ^ 0 = 0
0 ^ 0 = 0
1 ^ 1 = 0
1 ^ 0 = 1
1 ^ 1 = 0
So the final XOR of hex byte 87 and hex byte A5 would be binary 00100010 (which is also hex 22).
Next, we'd move onto comparing the previous result (ie. binary 00100010) with the next hex byte "03"
hex 22 = binary 00100010 hex 03 = binary 00000011
(hex 22 bit) ^ (corresponding hex 03 bit)
0 ^ 0 = 0
0 ^ 0 = 0
1 ^ 0 = 1
0 ^ 0 = 0
0 ^ 0 = 0
0 ^ 0 = 0
1 ^ 1 = 0
0 ^ 1 = 1
So the final XOR of hex byte 22 and hex byte 03 would be binary 00100001 (which is also hex 21).
We'd continue calculating the summation of hex XORs in this manner until all of the hex bytes in the original hex string were processed. The end result would be the checksum and in the case of the CSAFE protocol, the resultant hex byte would be included as the last byte of the data sent in transmissions from the exercise bike to the host program. In the CSAFE protocol, the cksum value is important since the host program either sees a valid cksum and processes the data, or sees an invalid cksum and tosses out the request.
Shed any light? Do it manually
![Surprised](https://passionford.com/forum/images/smilies/bigcry.gif)
![Surprised](https://passionford.com/forum/images/smilies/bigcry.gif)
ETA: The above is from a quick google, I'm not that good at this
![Surprised](https://passionford.com/forum/images/smilies/bigcry.gif)
Last edited by littleknocks; 21-10-2010 at 11:15 PM.
#13
BANNED
BANNED
iTrader: (1)
Join Date: Jul 2003
Location: Wiltshire
Posts: 12,483
Likes: 0
Received 0 Likes
on
0 Posts
![Default](https://passionford.com/forum/images/icons/icon1.gif)
Originally Posted by littleknocks
Infinity, or so it seems ![Confused](https://passionford.com/forum/images/smilies/icon_confused.gif)
The manual way of computing an XOR cksum would be to take each hex byte, convert it to binary & get the result of the XOR with the previous hex byte.
![Confused](https://passionford.com/forum/images/smilies/icon_confused.gif)
The manual way of computing an XOR cksum would be to take each hex byte, convert it to binary & get the result of the XOR with the previous hex byte.
The correct way to XOR 2 values is to convert each value straight to a binary value then bit for bit perform the XOR test....
Example 3351 = 1234 xor 2501
1234 decimal = 010011010010
2501 decimal = 100111000101
3351 decimal = 110100010111
Windows calculator (in scientific mode) is your friend...
![Grin](https://passionford.com/forum/images/smilies/icon_smile.gif)
Last edited by ECU Monitor Enthusiast; 22-10-2010 at 10:38 AM.
#15
Spelling Club King!
iTrader: (1)
![Default](https://passionford.com/forum/images/icons/icon1.gif)
01001 00010010010011100 100101 10 1000100100100 0100101 01 01 010 101001000010111 111000100101010010010 100 10 01 001 00 100 100 010 0001 001 01001 001001 100101001 001 0001 00 010010010 101 000101 010010011100 100101 10 1000100100100 0100101 01 01 010 101001000010111 111000100101010010010 100 10 01 001 00 100 100 010 0001 001 01001 001001 100101001 001 0001 00 010010010 101 000101 010010011100 100101 10 1000100100100 0100101 01 01 010 101001000010111 111000100101010010010 100 10 01 001 00 100 100 010 0001 001 01001 001001 100101001 001 0001 00 010010010 101 000101 010010011100 100101 10 1000100100100 0100101 01 01 010 101001000010111 111000100101010010010 100 10 01 001 00 100 100 010 0001 001 01001 001001 100101001 001 0001 00 010010010 101 000101
Stick that in your pipe and smoke it!
Stick that in your pipe and smoke it!
#16
![Default](https://passionford.com/forum/images/icons/icon1.gif)
01001 00010010010011100 100101 10 1000100100100 0100101 01 01 010 101001000010111 111000100101010010010 100 10 01 001 00 100 100 010 0001 001 01001 001001 100101001 001 0001 00 010010010 101 000101 010010011100 100101 10 1000100100100 0100101 01 01 010 101001000010111 111000100101010010010 100 10 01 001 00 100 100 010 0001 001 01001 001001 100101001 001 0001 00 010010010 101 000101 010010011100 100101 10 1000100100100 0100101 01 01 010 101001000010111 111000100101010010010 100 10 01 001 00 100 100 010 0001 001 01001 001001 100101001 001 0001 00 010010010 101 000101 010010011100 100101 10 1000100100100 0100101 01 01 010 101001000010111 111000100101010010010 100 10 01 001 00 100 100 010 0001 001 01001 001001 100101001 001 0001 00 010010010 101 000101
Stick that in your pipe and smoke it!
Stick that in your pipe and smoke it!
![Surprised](https://passionford.com/forum/images/smilies/bigcry.gif)
#17
10K+ Poster!!
Thread Starter
iTrader: (1)
Join Date: May 2003
Location: Lancashire
Posts: 12,748
Likes: 0
Received 0 Likes
on
0 Posts
![Default](https://passionford.com/forum/images/icons/icon1.gif)
I'm using Omron CX-Programmer for this function.
I have a number being generated using the seconds variable on the PLC RTC and adds this to the previous number generated. This is then multiplied by a factor that I can't remember as it was wrote in 2004. This number changes every PLC scan which is approx every 2ms.
1/ The code is using the date in ddmm format and XOR's with a known 4 digit number (number A as we shall call it).
2/ The result of step 1 is then XOR'ed with another known 4 digit number (number B).
3/ Number B is is then XOR'ed with another known 4 digit number (number C).
4/ The result of step 3 is then XOR'ed with the result of step 2.
5/ the result of step 4 is then OR'ed with the scrolling number from the RTC
This is done with values held in the data memory area of the PLC.
There is more to it than this but what I am trying to get my head round is what the result of 2 values would be.
So the function is converting the values to binary for the calculation to take place?
It's been a while since I worked with binary!!
I have a number being generated using the seconds variable on the PLC RTC and adds this to the previous number generated. This is then multiplied by a factor that I can't remember as it was wrote in 2004. This number changes every PLC scan which is approx every 2ms.
1/ The code is using the date in ddmm format and XOR's with a known 4 digit number (number A as we shall call it).
2/ The result of step 1 is then XOR'ed with another known 4 digit number (number B).
3/ Number B is is then XOR'ed with another known 4 digit number (number C).
4/ The result of step 3 is then XOR'ed with the result of step 2.
5/ the result of step 4 is then OR'ed with the scrolling number from the RTC
This is done with values held in the data memory area of the PLC.
There is more to it than this but what I am trying to get my head round is what the result of 2 values would be.
So the function is converting the values to binary for the calculation to take place?
It's been a while since I worked with binary!!
#18
PassionFord Post Troll
iTrader: (3)
![Default](https://passionford.com/forum/images/icons/icon1.gif)
Not quite right,
The correct way to XOR 2 values is to convert each value straight to a binary value then bit for bit perform the XOR test....
Example 3351 = 1234 xor 2501
1234 decimal = 010011010010
2501 decimal = 100111000101
3351 decimal = 110100010111
Windows calculator (in scientific mode) is your friend...![Grin](https://passionford.com/forum/images/smilies/icon_smile.gif)
The correct way to XOR 2 values is to convert each value straight to a binary value then bit for bit perform the XOR test....
Example 3351 = 1234 xor 2501
1234 decimal = 010011010010
2501 decimal = 100111000101
3351 decimal = 110100010111
Windows calculator (in scientific mode) is your friend...
![Grin](https://passionford.com/forum/images/smilies/icon_smile.gif)
![Top](https://passionford.com/forum/images/smilies/smile011.gif)
#20
Too many posts.. I need a life!!
Join Date: Nov 2008
Location: Notts
Posts: 549
Likes: 0
Received 0 Likes
on
0 Posts
![Default](https://passionford.com/forum/images/icons/icon1.gif)
Can I ask what the program is trying to do? And what the intended effect of multiplying the date with the 'factor A' is?
Is it something to keep the RTC a little more in line with reality?
Is it something to keep the RTC a little more in line with reality?
#22
10K+ Poster!!
Thread Starter
iTrader: (1)
Join Date: May 2003
Location: Lancashire
Posts: 12,748
Likes: 0
Received 0 Likes
on
0 Posts
![Default](https://passionford.com/forum/images/icons/icon1.gif)
It does Simon. I've been using this code for years but it was co-written by my predecessor and another software engineer. The time has come to write a new one. I've never really done much with mathematical calculations with PLC's before. Just simple data comparrison and movement.
Basically it's a code and anti-code generator. It gives you a 5 digit code and you must give it the correct 5 digit 'answer' back.
Basically it's a code and anti-code generator. It gives you a 5 digit code and you must give it the correct 5 digit 'answer' back.
Thread
Thread Starter
Forum
Replies
Last Post
Rich@rd
General Car Related Discussion.
15
15-07-2004 09:26 PM