Shop OBEX P1 Docs P2 Docs Learn Events
Fast method for Reverse Sign Extend? — Parallax Forums

Fast method for Reverse Sign Extend?

T ChapT Chap Posts: 4,223
edited 2015-01-20 19:57 in Propeller 1
I want to send out a signed long as a signed word, but don't see an operator that is the reverse of the signed extend from 15 to 31. I was wondering if there was a fast method in SPIN as single operator to move bit 31 to 15. Does anyone have a trick for a the fastest method in SPIN to move bit 31? All I can think of is:
If SignedLongVariable < 0
   WordVariable :=   %1000_0000_0000_0000  |=   SignedLongVariable   ' value does not exceed +/- 2000

' compute checksum
ser.tx(PacketHeader)
ser.tx(PacketLength)
ser.tx(Opcode)
ser.tx(WordVariable)
ser.tx(WordVariable>>8)
ser.tx(checksum)



Or
   WordVariable :=   SignedLongVariable +   SignedLongVariable  >> 16 

Comments

Sign In or Register to comment.