LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Even Parity Resultant from a Long String

Solved!
Go to solution

Hello, 

 

I have been trying to create a simple VI that takes a string of 4142312E3003 and creates a string with the hexadecimal code that would make it Even parity.

 

I want to achieve serial XOR of each element.  An Odd number of 1's returns a 1, an Even number of 1's returns a 0.

 

For example: 

 

Hex               Binary

41                  0100 0001 

42                  0100 0010

31                  0011 0001

2E                  0010 1110

30                  0011 0000

03                  0000 0011

 

Even Parity is 2F:  0010 1111 

 

I only want the resultant output of the string to be 2F. 

 

I have attached a VI but I'm not sure if it is what I should really use to achieve this. 

 

I would appreciate any feedback you may have. 

 

Many Thanks

0 Kudos
Message 1 of 12
(3,655 Views)

You should use string to byte array to turn your string into a numeric, then you can XOR all the components in a for loop (there isn't an array XOR as far as I'm aware).

XOR.png

I leave it to you to decide what to do with the resulting number.

Please note that unlike your example, I've used the HEX representation in the string as I figured that was most likely. If you are using decimal strings, you'll have to do a conversion.

Ian
LabVIEW since 2012
Message 2 of 12
(3,629 Views)

Hi Ian,

 

Many Thanks for your reply.

 

I am currently getting parity value of 76 rather than 2F. Does this have something to do with decimal conversion?


The string is being sent as 4142312E3003 in normal mode of the indicator.

0 Kudos
Message 3 of 12
(3,622 Views)

That is correct. In that case you will have to convert your string differently using the Hex string to number function as before. Here is something that might be useful:

https://lavag.org/topic/2697-trying-to-convert-string-to-byte-array-harder-then-i-expected/

It has an example further down of converting the "Hex" string to a byte array, then you can do the same XOR as I had in the post above.

Ian
LabVIEW since 2012
0 Kudos
Message 4 of 12
(3,614 Views)
Solution
Accepted by topic author neunited

@neunited wrote:

The string is being sent as 4142312E3003 in normal mode of the indicator.


In that case, you need to loop through the string and convert two characters into a number using the Hexadecimal String To Number and then the XOR.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 12
(3,609 Views)

Hi Crossrulz, 

 

Many thanks for providing your solution - how did you make the U8 constant "00"?

 

Even_parity.PNG

0 Kudos
Message 6 of 12
(3,551 Views)

Right-click on the constant and choose "Display Format".  I guess you know that just changes the appearance, and that was what you were after?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 12
(3,549 Views)

@billko wrote:

Right-click on the constant and choose "Display Format".  I guess you know that just changes the appearance, and that was what you were after?


There was a reason why I wanted to alter that. 

 

This is an example of what my even parity check resultant is performing at the moment: 

41    0100 0001

56    0101 0110

31    0011 0001

30    0011 0000

2E   0010 1110

30   0011 0000

03   0000 0011

 

Even parity check resultant is coming out as B, but actually it should be 0B. So I thought the "00" would do the trick but unfortunately it still comes out as B at the moment. This is important because the hex of B is 42 and hec of 0B is 3042. 

 

Does that make sense? 

0 Kudos
Message 8 of 12
(3,540 Views)

neunited wrote:

how did you make the U8 constant "00"?

 


The simple way is to right-click on choose Display Options.  You can specify the minimum number of characters to have and whether to pad with 0s or spaces.

 

Personally, I use a QuickDrop shortcut I made (Format Numeric).  The format in this case is %02x


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 12
(3,538 Views)

@crossrulz wrote:

neunited wrote:

how did you make the U8 constant "00"?

 


The simple way is to right-click on choose Display Options.  You can specify the minimum number of characters to have and whether to pad with 0s or spaces.

 

Personally, I use a QuickDrop shortcut I made (Format Numeric).  The format in this case is %02x


That's what I meant: "Display Options".  I was just winging it.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 10 of 12
(3,535 Views)