LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Binary String to Byte Array

Is there a simple function that will convert a binary string into a byte array?

For example:

Given:  "1 00001111 10100101 00001111"  (spaces won't be there  - I put those in here to make it easier to visually parse ..)

Byte Array : 0x0F       (lsb)
                    0xA5
                    0x0F
                    0x01        (msb)

I know I can take one character at a time and build my own bytes and add them to an array, I was just wondering if there was a function that already did it (or some hints on how to do it easily).


0 Kudos
Message 1 of 3
(4,583 Views)

Hello rfolea,

Thank you for posting on the NI Discussion Forums.  Unfortunately, there are no format codes which specify exactly what you are trying to do.  When you read in a string of “1010” and format it to hexadecimal (using Fmt( ) with “%x<%s” as the format code), it literally converts “1010” to 0x1010, instead of 0xA like you are trying to do.  So to say it plainly, there is no function that will take care of this conversion for you.  As you proposed above, you must parse the string and convert every grouping of four characters into its corresponding hexadecimal representation.

Chris_G
Sr Test Engineer
Medtronic, Inc.
0 Kudos
Message 2 of 3
(4,562 Views)

Thanks Chris,

 

I went ahead and did the brute force method, works fine.  Was just wondering if something already existed ...

 

Thankyou for taking the time! 

0 Kudos
Message 3 of 3
(4,559 Views)