LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Hexadecimal string -> representation?

*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!!

 

0 Kudos
Message 1 of 4
(2,416 Views)

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.

Message 2 of 4
(2,388 Views)

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.

 

ReverseTheBits.png

Message 3 of 4
(2,366 Views)

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


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 4
(2,354 Views)