Archived

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

ggs

Bitwise algebra question

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)

var
  value : longword;
...
value := ...
if (value and $80000000) <> 0 then
  value := value xor ($FFFFFFFF)
else
  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