09-05-2017 09:48 AM - edited 09-05-2017 10:09 AM
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
Solved! Go to Solution.
09-05-2017 10:27 AM
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).
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.
09-05-2017 10:59 AM
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.
09-05-2017 11:06 AM
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.
09-05-2017 11:31 AM - edited 09-05-2017 11:32 AM
@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.
09-11-2017 11:10 AM
Hi Crossrulz,
Many thanks for providing your solution - how did you make the U8 constant "00"?
09-11-2017 11:16 AM
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?
09-11-2017 11:24 AM
@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?
09-11-2017 11:26 AM
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
09-11-2017 11:28 AM
@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.