12-06-2012 02:10 AM
I tried as the attached, but seems both not right. The FBFF should be negative, but both give positive.
12-06-2012 02:23 AM
(64511-65535 =-1024) Perhaps I missed something.
Do you know How the negative number is represented in 2's complement.
Condition I give was wrong but value 65535 is right its equivalent to FFFF in hex.
12-06-2012 02:31 AM - edited 12-06-2012 02:40 AM
@alex. wrote:
The data is in16bit, little-endian, 2’complement format.
Eg. “60 02” is a little-endian notation, it equals to 0x0260, 608 in decimal.
Also “FF FB” means -1025.
Simply use unflatten from string (little endian, type I16) and the rest will fall into place. 😄
(The FOR loop is just to do it on both inputs. In general it is a one step operation ;)))
You say that the data is big? If it is a long string, use the same function, but use an array of I16 as type. No FOR loop needed.
12-06-2012 02:37 AM
I got it,
Compare the number with (F000)hex i.e. (61440)dec. If the input no. is higher than this than it is negative substract the no. from 65536 to get the negative no.
for ex. FBFF=64511in decimal, it is greater the 61440. Hence 65536-64511= 1025
FFFB= 65531in decimal and 4 is the negative value.
12-06-2012 02:40 AM - edited 12-06-2012 02:43 AM
@alex. wrote:
I tried as the attached, but seems both not right. The FBFF should be negative, but both give positive.
That's because FBFF as a string is not the same as \FB\FF in a string set to \ codes display. The typecast will work properly if you set the string for \ codes and enter \FB\FF (which is how your earlier image showed it). Also make sure that the type (the center input) to the typecast is a signed 16-bit value (I16).
EDIT: or, if your string was set to Hex display, then what you have should work, in which case I'm guessing the problem is the target type of the typecast.
12-06-2012 02:42 AM
@Aojha wrote:
Hi Natahand,
I think typecasting would not show negative numbers.
You would be wrong. Why would you think this? Did you try testing it? All you needed to do was drag the image I posted into a block diagram and run it to prove that it works. You seem to be very interested in making this much more complicated than necessary (of course, as usual Altenbach has the simplest solution).
12-06-2012 02:45 AM
Stop the insanity!!!
All you need is one step as I showed above. No splitting, concatenating, swapping, adding, subtracting, or whatever. 😄
12-06-2012 02:49 AM
I tried as the attached vi, but seems not -1025
12-06-2012 02:52 AM
Hi,
I am also new in Labview, and tried to solve it by whatever little knowledge I have.
Sorry if I have hurt your feelings
12-06-2012 02:59 AM - edited 12-06-2012 03:01 AM
@alex. wrote:
I tried as the attached vi, but seems not -1025
That's because your string in the attached vi is not in hex, it's in ASCII. Which is it supposed to be? Your own data example was in hex.