This topic is now archived and is closed to further replies.

Bitwise algebra question

This topic is 5286 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m trying to implement a radix sort working with single precision floatpoint values. I''ve gotten it to work, and now I''m trying to improve it sections of the code which I needed to alter from my normal radix sort to get it to handle negatives correctly. In my inner loops(biulding the histogram & the each loop for each byte position) I have the following:
// When the sign bit is set, xor with 0xFFFFFFFF (flip every bit)

// When the sign bit is unset, xor with 0x80000000 (flip the sign bit)

  value : longword;
value := ...
if (value and $80000000) <> 0 then
  value := value xor ($FFFFFFFF)
  value := value xor ($80000000);
I use this to force negative values to be sorted correctly. Simply put, how do I get rid of the conditional statement? Also I run my code with interger overflow detection enabled(I like the extra data valitation)

Share this post

Link to post
Share on other sites
Never mind. Figure it out for my self.

value := value xor ( Longword(-Integer(value shr 31)) or $80000000 );

Share this post

Link to post
Share on other sites