Sign in to follow this  
Followers 0
sbaum

UDINT to DINT

7 posts in this topic

Ok this one seems like it should be easy but I'm coming up dry on the easy way... I have a double word (unsigned) I'm reading from a scale transmitter. The sign is being sent as a separate bit. I need to convert the double unsigned word to a double signed word (DINT)

Share this post


Link to post
Share on other sites
Why not simply force the sign bit of the DINT ON (or OFF) based to your separate bit. If the sign bit is ON (negative) then subtract the current value from zero. If it's OFF just leave it as is. Edited by Mendon Systems

Share this post


Link to post
Share on other sites
Easy enough... Which bit is the sign bit for a double word??

Share this post


Link to post
Share on other sites
The fifteenth bit of the high word.

Share this post


Link to post
Share on other sites
These are two separate suggestions. The 2nd suggestion is absolutely correct, if the sign bit is separate. The 1st, however is wrong. Inverting only the leftmost bit in a word is not enough for proper change of the value sign. Edited by Sergei Troizky

Share this post


Link to post
Share on other sites
Well ... yeah! I guess I didn't word that very well. To get the negative value he has to subtract the positive value from zero. He should do that when his external sign bit is ON (assuming of course that ON means negative).

Share this post


Link to post
Share on other sites
Yes ok Sergei, I worded that question incorrectly! I was wondering which bit is the sign WITHIN the double word. And yes I had previously tried inverting the leftmost bit and that didn't work. I will subtract the value from zero. That makes sense. Edited by sbaum

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0