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: 

string to binary

hi,
what i have is a string control with hex values in it.  i need to convert to binary and put each bit into its own index in an array.  but i am having a problem with conversion because the hex string control is in "Normal" Display Style(properties menu) and not in "Hexadecimal" display mode.  i've been messing around with it but can't seem to get it to work.  i attached the data set.

thanks
0 Kudos
Message 1 of 8
(14,633 Views)
tried doing a
1. hex string to number conversion
2. number to boolean array
3. boolean array to 0,1

but not working
Message 2 of 8
(14,620 Views)
How is it not working?  If I put in "FF" into the string, I get a 1 in bits 0 through 7 and a 1 in the array indexes 0 through 7.
 
Do you want your input string to be a series of characters that represent a hexadecimal value such as " F F A 0 7 "?  Or do you want a series of bytes where each byte would appear in hex such as FF 0A B8  ?
 
If the latter, then the string to byte array function may help.  Also look at the typecast function.
0 Kudos
Message 3 of 8
(14,609 Views)

Here you can find how to convert a string to binary(I changed the display format to hexa 😉 to see more clearly my message).
I made it for 3 bytes length a message

Enjoy

Message 4 of 8
(10,858 Views)

Is there a reason to add this to a 6 year old thread?

 

The person who posted this question hasn't logged into the forums in almost as long.

0 Kudos
Message 5 of 8
(10,831 Views)

I ramarked that the question has been written 6 years ago ;).
It's just to help others how are dealing with the same issue ^_^.
I had the same problem before writing the solution. So I think that it could be useful for others. 
Have a nice day 😉  and hope that you'll do the same for questions not answered ^_^ 

0 Kudos
Message 6 of 8
(10,803 Views)

You did not remark in your message that the thread was 6 years old.

 

And an answer was given in this thread.  I was the one who answered the thread.  It just so happened that the original poster never came back and said they needed any more help.

0 Kudos
Message 7 of 8
(10,784 Views)

Abdelhakim_ZOUAKI wrote:

It's just to help others how are dealing with the same issue ^_^.
I had the same problem before writing the solution.


How is that the same issue. here is what you attached:

 

 

First of all, you posted very specialized code that translates a binary string diagram constant with exactly three characters into three different boolean arrays named "header #" (for some unknown reason). It has nothing to do with the original question and has very little to do with "binary". It is not the "same problem" by a long shot. The various headers are not even arranged in any logical order.

 

Then your code is also way too complicated., for example, you don't need to wire the indices if you want the first three elements in order. The code is also not scalable, because you need to do significant modifications if you later require a program that does the same for longer or shorter strings. The program also does not check if the string is the correct lenght, making it hard to tell if something is wrong.

 


Abdelhakim_ZOUAKI wrote:

So I think that it could be useful for others. 
Have a nice day 😉  and hope that you'll do the same for questions not answered ^_^ 


No, it is not useful in the current form. I challenge you to simplify and generalize your program to take strings of any lenght and convert it into a single boolean array of the correct lenght.  A good exercise. Try it! 🙂

 

 

 

0 Kudos
Message 8 of 8
(10,771 Views)