From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Conversion Problem

Solved!
Go to solution

I want to be able to input a decimal 7 characters long:

 

ie: 1666461

 

I then need a function to split the number first three characters and the last four characters:

 

ie: 166    6461

 

I then need it to convert those two numbers into two binary numbers:

 

ie: 10100110           0001100100111101

 

I then need it to do add a parity bit (even = 1 odd = 0) to each binary number like so:

 

110100110          000110001001111010

 

 

I then need it to combine the two numbers into a single string:

 

110100110000110001001111010

 

this 26bit number can then be sent to an output...

 

Hope anyone can advise.  New to labview here throw me a bone! Smiley Frustrated

 

Thank you all


 

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

If you are new to LabVIEW, you should learn first.

 

Do you need to verify the number and lexical class characters in the input string? It might be better to use a numeric integer control and just verify the formatted decimal length. Once it is a formatted string, there are plenty of tools in the string palette to split it into two strings. Now simply format each part back into a numeric integer datatype and then format that as binary string. Calculate the parity ((it is not clear at all how you calculate parity here. Please clarify!) Use concatenate string resized to four inputs to prepend/append the parity and merge the two strings.

 

 

Message 2 of 12
(3,020 Views)

A place to start:

 

Convert the number to a decimal string

Split the string

String to Number

Number to Bool Array

Insert in to array (parity bits)

For each item in array, bool to 0,1

Number (0, 1) to decimal string

Concatinate strings

Message 3 of 12
(3,018 Views)

What format do you need to output?  Boolean Array?  String of 0s and 1s?


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 4 of 12
(3,005 Views)

After some headache 🐵 I now have 2 subset Boolean arrays - 

 

The first is an array of 12 bits

The second an array 12 bits

 

Great that’s what I want! - I now have to carry out the parity check on those arrays –

 

The First array (subset):

 

RULE: The first 13 bits of the overall 26 bits - has to have an even number of 1’s!

RULE: The second 13 bits of the overall 26 bits – has to have an odd number of 1’s!

 

The parity will be there to add a 1 to the beginning of the array (if) in the first 12 bits consists of an odd number of ones (1’s) or add a ‘0’ at the beginning of the array (if) the 12 bit array already has an even number of 1’s.

 

For example: 101001100001 will become 1101001100001 as there originally was only 5 1’s in the 12 bit array.

 

For the second array of 12 bits the added parity bit is added at the end of the array – remember this has to end up as a 13 bit array with an odd number of 1’s:

 

For example:  100100111101 will become 1001001111010 as there is already an odd number of 1’s.

 

At this point what I should have is 2 x 13 bit arrays which need to be concatenated into a single Boolean array.

 

Example:  11010011000011001001111010

 

I have attached a screen shot of my code - to show how I have got to this stage.  Hope you can advise.

 

Thanks again

 

Neil

0 Kudos
Message 5 of 12
(2,963 Views)

First of all, lets get rid of some of those Rube Goldbergs.

 

If you have a decimal number and you want the separate it to 3 and 4 digits, use Quotient & Remainder to divide by 10000.  That way you aren't converting to and from strings.  Then you can use the Number To Boolean Array to get your boolean arrays.  Use Array Subset to get only the bits you care about.

 

Now keep the arrays seperate.  There's no need to bring them together just to split them up again.

 

The easiest way to do a parity check is with a FOR loop and an XOR.  Use a shift register to keep the current parity bit value and XOR it with the autoindexing of the array.  Initialize the shift register to FALSE for even parity, TRUE for odd parity.  From there, you just need to build up your array and possibly reverse it to get it to display the way you want.

 


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 6 of 12
(2,944 Views)
Wait a minute. You changed your requirements. In your first post you have arrays of 8 and 16 bits. Now you have two arrays of 13.

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 7 of 12
(2,935 Views)
Solution
Accepted by topic author hawkstringer

Thanks for you help,  that great! I did have to change a couple of bits - I needed to build and re-split the array into 2 to get 2 lots of 12. I attach my code to confirm.  it works... but if it can be cleaned up even more let me know.

 

Its a far cry from what I started out with this morning Rube etc... Smiley Happy

 

Thanks again.

 

Conversion_Problem_Solution.png

0 Kudos
Message 8 of 12
(2,910 Views)

You should mark CrossRulz's message as the solution to your problem rather than your own message, since it appears you pretty much used the code he provided.  (First you will have to unmark yours by going to the Options menu to the upper righ to of your message.)

0 Kudos
Message 9 of 12
(2,906 Views)

I would also rethink this data format.  The max value for the second half of the value is 9999.  To represent that, you need 14 bits.  Assuming 3 digits for the first half, the max value is 999, which needs 10 bits.  So you are losing data.  I somehow doubt that is what you want.

 

You are also being very inconsistant with your requirements.  You started out saying that you will have a 7 digit number.  But your last example that you marked "solved" has an 8 digit number.  So what EXACTLY are your requirements?  And what is this really trying to do?


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 10 of 12
(2,894 Views)