03-08-2013 09:57 PM
Hi,
I tried to do a 9-bit 2's complement to determine the signed bit. I wrote in text-based, and it was work fine; however, I tried to convert LabVIEW. It seem that the digital thermometer is not taking a negative temperature. Could anybody help me look through this code? Here is the text-based code.
if ((tempdata & 256) == 256
tempdata = ((((tempdata & 255) ^ 255) + 1) * -1);
else
tempdata;
When I used the "Read Field" module to read a 16-bit temperature data, but I only care bit 7-15. However, the "Read Field" module takes care extracting the data into 9-bit. The data that I read from the "Read Field" module is returned to numeric U32. So I used the returned data determine if the MSB is equal to one.
Solved! Go to Solution.
03-08-2013 10:12 PM
I don't understand the ^255 within your text based code.
However the AND 255 makes sense to get the 8 bits. However you aren't doing that in your LabVIEW code. The Number to Boolean is going to give you a 16-element boolean array (assuming the blue wire coming from the read subVI is 16 bit.) And you are never masking off those 8 bits. I'm not so sure you even need to do any conversions from number to boolean array and back again.
03-11-2013 01:28 PM
Hi,
Thank you for your quick input. I also confused myself. Maybe I should write in this sequence.
1. The module "Read Field" will read the 16 bit temperature data from a device, returned to the output as U32 data type. The module automatically takes care extracting the bit D15-D7.
2. So I used the unsigned 32 bit decimal number to determine the MSB bit (I'm not sure if I do need to convert back to binary).
3. Do a 2's complement mathematical operation to get the negative sign.
4. Multiply by 0.5C because the device temp (C) is LSB = 0.5C.
I have attached the file. Please advise if this is correct. I checked by entering the number. Would you please show me how to implement two complement in LabVIEW. Please help! Thanks.
03-11-2013 01:36 PM
Should I use the FXP?
03-11-2013 02:04 PM
When you are doing a bit operation, you shouldn't forget to verify position still. Your case statement with "1" isn't valid. It needs to be "256".
This should be the result you're looking for.
"I won't be wronged. I won't be insulted. I won't be laid a-hand on. I don't do these things to other people, and I require the same from them." John Bernard Books
03-11-2013 07:13 PM
Hi bsvare,
Indeed, that's what I am looking for. Thank you so much for your help.
03-12-2013 06:27 PM - edited 03-12-2013 06:32 PM
Perhaps it's simpler to use the functions built-in for this. (See Numeric->Fixed-point palette)
(I screenshotted the properties dialog setup for the cast and added it to the BD for illustration only.)
Best regards,
Dave