Let's say I have a 16-bit number system. and let $a, b$ a 16-bit numbers in this system. I know that the numbers I can represent in this system are between $−32,768$ and $32,767$.

Let's say I want to compare between $a$ and $b$ where $a, b$ are near those limits. for example: $a=30,000$ and $b=-30,000$. I want to compare these numbers using only logical operators (using assembly-like language). I mean that I can't use '$<$' or '$>$' and I can use '$==$' only to compare with $0$.

So I thought about this idea: for determining if $a==b$, I can use the XOR and then check if the result equals $0$.

I want to figure out how to determine, using this method, if a is greater than b or if a is less than b?

I want hints and good thoughts, and maybe a different ideas than mine. In addition, if you think that the XOR'ing idea isn't useful or it won't work, I'd like to know why.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.