General Car Related Discussion. To discuss anything that is related to cars and automotive technology that doesnt naturally fit into another forum catagory.

Geeks -Exclusive Or function XOR

Thread Tools
 
Search this Thread
 
Old 21-10-2010, 05:46 PM
  #1  
DazC
10K+ Poster!!
Thread Starter
iTrader: (1)
 
DazC's Avatar
 
Join Date: May 2003
Location: Lancashire
Posts: 12,748
Likes: 0
Received 0 Likes on 0 Posts
Default Geeks -Exclusive Or function XOR

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?
Old 21-10-2010, 08:54 PM
  #2  
lead_foot
is awesome

iTrader: (1)
 
lead_foot's Avatar
 
Join Date: May 2005
Location: Chesham, Bucks
Posts: 4,802
Likes: 0
Received 0 Likes on 0 Posts
Default

One or the other but not both
Old 21-10-2010, 08:56 PM
  #3  
lead_foot
is awesome

iTrader: (1)
 
lead_foot's Avatar
 
Join Date: May 2005
Location: Chesham, Bucks
Posts: 4,802
Likes: 0
Received 0 Likes on 0 Posts
Default

a = 0 b = 0 then output is 0
a = 1 b = 0 then output is 1
a = 0 b = 1 then output is 1
a = 1 b = 1 then output is 0
Old 21-10-2010, 08:58 PM
  #4  
ECU Monitor Enthusiast
BANNED
BANNED
iTrader: (1)
 
ECU Monitor Enthusiast's Avatar
 
Join Date: Jul 2003
Location: Wiltshire
Posts: 12,483
Likes: 0
Received 0 Likes on 0 Posts
Default

Originally Posted by lead_foot
a = 0 b = 0 then output is 0
a = 1 b = 0 then output is 1
a = 0 b = 1 then output is 1
a = 1 b = 1 then output is 0

Thats a nice simple way of explaining it in basic terms
Old 21-10-2010, 09:23 PM
  #5  
St3V3_C
PassionFord Post Whore!!
 
St3V3_C's Avatar
 
Join Date: May 2003
Location: Bristol
Posts: 9,580
Received 42 Likes on 36 Posts
Default

This is how RAID uses a 500GB drive to safeguard 1TB of data.

That is cool.

Last edited by St3V3_C; 21-10-2010 at 09:24 PM.
Old 21-10-2010, 10:38 PM
  #6  
DazC
10K+ Poster!!
Thread Starter
iTrader: (1)
 
DazC's Avatar
 
Join Date: May 2003
Location: Lancashire
Posts: 12,748
Likes: 0
Received 0 Likes on 0 Posts
Default

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.
Old 21-10-2010, 10:41 PM
  #7  
botters
competant bodger
iTrader: (2)
 
botters's Avatar
 
Join Date: May 2009
Location: preston
Posts: 6,234
Received 23 Likes on 21 Posts
Default

eh?
Old 21-10-2010, 10:45 PM
  #8  
AJC
10K+ Poster!!

iTrader: (6)
 
AJC's Avatar
 
Join Date: Oct 2004
Location: Preston, Lancs
Posts: 13,366
Received 83 Likes on 73 Posts
Default

WTF daz
Old 21-10-2010, 10:48 PM
  #9  
botters
competant bodger
iTrader: (2)
 
botters's Avatar
 
Join Date: May 2009
Location: preston
Posts: 6,234
Received 23 Likes on 21 Posts
Default

andy i suggest we leave this thread immediatley our fragile little minds cannot comprehend such things
Old 21-10-2010, 10:54 PM
  #10  
Escow-Van
Too many posts.. I need a life!!
 
Escow-Van's Avatar
 
Join Date: Nov 2008
Location: Notts
Posts: 549
Likes: 0
Received 0 Likes on 0 Posts
Default

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...
Old 21-10-2010, 11:14 PM
  #11  
littleknocks
PassionFord Regular
 
littleknocks's Avatar
 
Join Date: Aug 2006
Posts: 377
Likes: 0
Received 0 Likes on 0 Posts
Default

Originally Posted by DazC
Ok, so if I had an input figure of 3642 and another of 1532, what would the outcome be?
Infinity, or so it seems

Originally Posted by DazC
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.
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.

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

ETA: The above is from a quick google, I'm not that good at this

Last edited by littleknocks; 21-10-2010 at 11:15 PM.
Old 21-10-2010, 11:22 PM
  #12  
botters
competant bodger
iTrader: (2)
 
botters's Avatar
 
Join Date: May 2009
Location: preston
Posts: 6,234
Received 23 Likes on 21 Posts
Default

my brain hurts
Old 22-10-2010, 10:37 AM
  #13  
ECU Monitor Enthusiast
BANNED
BANNED
iTrader: (1)
 
ECU Monitor Enthusiast's Avatar
 
Join Date: Jul 2003
Location: Wiltshire
Posts: 12,483
Likes: 0
Received 0 Likes on 0 Posts
Default

Originally Posted by littleknocks
Infinity, or so it seems



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.
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...

Last edited by ECU Monitor Enthusiast; 22-10-2010 at 10:38 AM.
Old 22-10-2010, 12:50 PM
  #14  
martysmartie
PassionFord Post Whore!!
iTrader: (1)
 
martysmartie's Avatar
 
Join Date: Dec 2007
Posts: 8,461
Received 103 Likes on 101 Posts
Default

Originally Posted by botters
my brain hurts
There talking about logic gates.

Martin
Old 22-10-2010, 01:19 PM
  #15  
DanW@FastFord
Spelling Club King!
iTrader: (1)
 
DanW@FastFord's Avatar
 
Join Date: Oct 2007
Location: Fast Ford
Posts: 10,415
Received 21 Likes on 15 Posts
Default

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!
Old 22-10-2010, 01:34 PM
  #16  
littleknocks
PassionFord Regular
 
littleknocks's Avatar
 
Join Date: Aug 2006
Posts: 377
Likes: 0
Received 0 Likes on 0 Posts
Default

Originally Posted by DanW@FastFord
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!
That's R2-D2's chat up line
Old 22-10-2010, 01:48 PM
  #17  
DazC
10K+ Poster!!
Thread Starter
iTrader: (1)
 
DazC's Avatar
 
Join Date: May 2003
Location: Lancashire
Posts: 12,748
Likes: 0
Received 0 Likes on 0 Posts
Default

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!!
Old 22-10-2010, 05:47 PM
  #18  
fraser9764
PassionFord Post Troll
iTrader: (3)
 
fraser9764's Avatar
 
Join Date: Oct 2006
Location: Cheshire
Posts: 3,070
Received 29 Likes on 23 Posts
Default

Originally Posted by ECU Monitor Enthusiast
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...
this
Old 22-10-2010, 05:53 PM
  #19  
fraser9764
PassionFord Post Troll
iTrader: (3)
 
fraser9764's Avatar
 
Join Date: Oct 2006
Location: Cheshire
Posts: 3,070
Received 29 Likes on 23 Posts
Default

Originally Posted by DazC
So the function is converting the values to binary for the calculation to take place?
yes
can i ask what you are doing? cant say ive seen anything quite like that before? although it is difficult to understand when you are reading it in text form.
Old 22-10-2010, 06:31 PM
  #20  
Escow-Van
Too many posts.. I need a life!!
 
Escow-Van's Avatar
 
Join Date: Nov 2008
Location: Notts
Posts: 549
Likes: 0
Received 0 Likes on 0 Posts
Default

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?
Old 23-10-2010, 08:43 AM
  #21  
ECU Monitor Enthusiast
BANNED
BANNED
iTrader: (1)
 
ECU Monitor Enthusiast's Avatar
 
Join Date: Jul 2003
Location: Wiltshire
Posts: 12,483
Likes: 0
Received 0 Likes on 0 Posts
Default

The omron PLC should have an instruction that can xor 2 word values easily
Old 23-10-2010, 09:12 AM
  #22  
DazC
10K+ Poster!!
Thread Starter
iTrader: (1)
 
DazC's Avatar
 
Join Date: May 2003
Location: Lancashire
Posts: 12,748
Likes: 0
Received 0 Likes on 0 Posts
Default

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.
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
YODI
Cars for Sale
5
30-08-2015 01:12 PM
tomiii
Restorations, Rebuilds & Projects.
12
18-08-2015 08:40 PM
Rich@rd
General Car Related Discussion.
15
15-07-2004 09:26 PM



Quick Reply: Geeks -Exclusive Or function XOR



All times are GMT. The time now is 11:25 PM.