LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

String to Byte Labwindows

I would like to use CVI to accomplish the same thing as the LabView String to Byte Array Function does. Is there a way to do this?

0 Kudos
Message 1 of 9
(4,846 Views)

Unless the LV function does something not obvious from it's name, you don't need to do anything in C. A string is already a byte array. Just index whatever byte you want:

 

char str[10] = "Hello World";

printf("%c%c", str[0],str[6]);// will output HW

Kevin B.
0 Kudos
Message 2 of 9
(4,841 Views)

Alright, but what if your string consists of characters such as: Âµ?

 

Quinn

0 Kudos
Message 3 of 9
(4,836 Views)

That's still just a single byte character so it works perfectly fine. Are you concerned about using multi-byte characters?

 

I looked up LabView's documentation and it looks like String To Byte Array just returns an array of unsigned bytes which is essentially the same thing as a string in C and it doesn't appear to handle multi-byte chars.

Kevin B.
0 Kudos
Message 4 of 9
(4,834 Views)

Yes.Thank you. I meant to put something like this one: ž. 

Do you know od any way to handle multi-byte characters in LabWindows?

 

Quinn

0 Kudos
Message 5 of 9
(4,819 Views)

CVI has a bunch of functions for handling multi-byte characters. I'd suggest taking a look at CmbIsLeadByte() which determines whether the byte you're looking at is the leadbyte of a multibyte character and theCmbStrInc()/CmbStrDec() functions which will move a pointer to either the next or previous character in a string. You could easily write your own String to MultiByte array function using those functions.

 

I'd suggest reading Programming for Multibyte Character Sets in LabWindows/CVI for a more detailed explanation of all the multi-byte functions CVI offers and how to use them.

Kevin B.
0 Kudos
Message 6 of 9
(4,817 Views)

Thank you very much!

I just have one other things I am confused about. You said that Âµ is still a single byte character but most online ASCII to Binary converters tell me that its binary conversion is: 11000010 10110101. Is this incorrect?

0 Kudos
Message 7 of 9
(4,814 Views)

The second byte, 10110101 is equivalent to 181, which is the location of Âµ in the extended ASCII table according to ISO Latin-1 (there are different 8-bit ASCII variations). I'm guessing that those bit values are the location of Âµ in Unicode, although in CVI (and many other text editors) that character can be found in standard 8-bit ASCII as well.

 

You can see the full Latin-1 table here.

Kevin B.
0 Kudos
Message 8 of 9
(4,811 Views)

Thank you very much! You have been extremely helpful.

 

Quinn

0 Kudos
Message 9 of 9
(4,807 Views)