10-18-2017 08:11 PM
*Attached VI for reference*
Hi,
I have created a basic VI here where I take an SGL input, typecast it I32, convert the endianness, and output a binary string. Afterwards, i scan the binary string to create a 32 bit, 8 digit hexadecimal string.
My problem is that there are some cases where the hex string is only 7 digits long, such as when i input an SGL of 2 - i get a hex string of 2000000. I am stuck on finding a way for it to be represented as 02000000. Another example is inputting an SGL of 0 - the hex string is just 0, but i need it to be represented as 00000000. Basically I always need the hex string to be 8 digit\32 bits for my purposes. Is there a relatively uncomplicated way i can achieve this?
Thanks in advance!!
10-18-2017 09:49 PM
That seems like convoluted manipulations. But I'm not going to decode what you are trying to do.
Check the inputs for the functions you use to convert to strings. Particularly "Width" on convert to Decimal String.
10-19-2017 02:51 AM - edited 10-19-2017 10:14 AM
bkcw95 wrote:I have created a basic VI here
Your VI is nothing "basic", it is Rube Goldberg all over. For example, you could just cast to a U32 scalar, not an array of I32 and eliminate the FOR loop. Same difference!
Assuming that your code is actually working correctly, the problem is that you don't do an endian conversion, but a bit reversion, because that's what you get in your code after doing the song and dance with the boolean array, etc. Are you really sure your code is correct?
Attached are two version of some simple code that both do the same as yours with arguably less code (but try it!). See if it can give you some ideas, then pick one of them. (The LUT returns a bit reversed value for each possible U8 value). These are just some simple ideas, I am sure they can be further improved.
And yes, as Ravens said, all you need to do is wire an 8 to the formatter at the end to pad with leading zeroes.
10-19-2017 06:05 AM - edited 10-19-2017 06:05 AM
Personally, I am a fan of the Flatten To String and Unflatten From String because the include the Endian option. And you can just use the Format Into String for both your boolean and hex strings. This does not include your bit reversal though (MSb is first in my strings).