Signed to unsigned

Started by
11 comments, last by ToohrVyk 18 years, 4 months ago
Quote:Original post by ToohrVyk
The post is correct, I do want to reverse the comparison.
It looks very much to me like your OP is reversing the comparison. If 5 > 3 you want F(3) > F(5).

I would simply add the offset required to make the most negative value equal to zero (which would be 0x80000000), then cast it to an unsigned.
In fact, that's exactly what I did in my signed bigint class. For a signed comparison it does just that, then calls the unsigned comparison functions.

I'm impressed that Nemesis2k2 also describes the reversal, which I hdan't thought of, and as others have mentioned, the add can be replaced with an xor.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
Advertisement
TBH, i didn't fully understand your question.

however, you might want to look into boost. theres a something called something along the lines of "numeric_cast"... this has saved my ass plenty of times (in networking code where i was always casting from signed / unsigned). it throws an exception if there is any loss of data.
FTA, my 2D futuristic action MMORPG
Thank you, everyone. I settled for the XOR-based solution.

This topic is closed to new replies.

Advertisement