LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

convert a hexadecimal array to signed integer

Solved!
Go to solution

I've created a hexadecimal array. I need to convert it to signed integer

For example if I input 'ff48' into the array, I should get -184 as the output. 

 

I tried creating a local variable from the Hexadecimal input and changing the representation to decimal, but then 'ff48' is being converting to unsigned integer, i.e., 65352.

 

Is there a way to do it?

 

I've also attached what I've done up till now.

 

Thanks.

 

 

0 Kudos
Message 1 of 7
(2,551 Views)
Solution
Accepted by topic author sarwatsarfaraz

Hi sarwat,

 


@sarwatsarfaraz wrote:

I've created a hexadecimal array. I need to convert it to signed integer


No, you did not create an array. You placed a default scalar control on your frontpanel!

No, you don't need to convert to "signed integer", it already is a signed integer as you set the I32 datatype!

 


@sarwatsarfaraz wrote:

For example if I input 'ff48' into the array, I should get -184 as the output. 


Set the datatype for both frontpanel elements to I16, then type FF48 into the control and run the VI:

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 7
(2,543 Views)

This worked.

 

But why doesn't I32 show signed integer and I16 does?

0 Kudos
Message 3 of 7
(2,524 Views)
Solution
Accepted by topic author sarwatsarfaraz

Hi sarwat,

 


@sarwatsarfaraz wrote:

But why doesn't I32 show signed integer and I16 does?


Because FF48 (I16) is something completely different than 0000FF48 (I32)…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 7
(2,520 Views)

I need to join multiple elements of an array into a single element. 

 

I've attached a picture of how i want it to be.

 

How can I do this?

sarwatsarfaraz_0-1658831669760.png

 

0 Kudos
Message 5 of 7
(2,506 Views)
Solution
Accepted by topic author sarwatsarfaraz

Hi sarwat,

 


@sarwatsarfaraz wrote:

I need to join multiple elements of an array into a single element. 


Several options:

  1. Index the elements you  want to join, then use the JoinNumbers function…
  2. Index the elements you want to join and apply basic math to calculate your number (y=256*a+b)…
  3. Use TypeCast…
  4. When your array represent bytes then you might use UnflattenFromString…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 7
(2,503 Views)
Solution
Accepted by topic author sarwatsarfaraz

@GerdW wrote:
4. When your array represent bytes then you might use UnflattenFromString…

You will need the Byte Array To String before the Unflatten From String.  But do note that the Byte Array To String is literally a No Op (takes no clock cycles or memory) since an array of bytes and a string have the exact same data format.

 

I will also state that I try to avoid the Type Cast and prefer the Unflatten From String due to the additional options with the Unflatten From String.


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
0 Kudos
Message 7 of 7
(2,475 Views)