Bitwise algebra question

Started by
0 comments, last by ggs 20 years, 8 months ago
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)
Advertisement
Never mind. Figure it out for my self.

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

This topic is closed to new replies.

Advertisement