LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Get value from array and convert it to decimal

Solved!
Go to solution

Hi,

 

My problem is this: I have an array where the array[3] and array[4] give me the size of that array. If you send an array of 30 bytes, array[3]=1 and array[4]=e, forming a 1e in hexadecimal that in decimal is 30. How can I do this operation in labwindows? That is, take those values, put them together and convert them to decimal.

 

I hope you explained me well,

0 Kudos
Message 1 of 4
(1,048 Views)

It looks like your array is a string (i.e. "1e"): if this is true, a simple sscanf () or Scan () with the appropriate conversion specifications will be enough.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 4
(1,041 Views)

Yes, i have a "1e" but separated. I mean, i have the 1 from one part and the e from the other. How can i joined them in an array?

0 Kudos
Message 3 of 4
(1,036 Views)
Solution
Accepted by mikelmujika

Well, a string actually is an array of bytes... I mean: string[5] = "ABCD" actually reads string[0] = "A", String[1] = "B", string[2] = "C", string[3] = "D", string[4] = 0 (note that this is a value, not the character "0"; it's the string terninator).

 

In your case since array[3[ = "1" and array[4] = "e" you could use sscanf (array + 3, "%2x", &value), obtaining value = 30. This is more a C question than a CVI one: may it be that you need to refresh your C language knowledge?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 4
(1,014 Views)