How to compute the integer absolute value without using if condition.
I guess we need to use some bitwise operation.
Can anybody help?
How to compute the integer absolute value without using if condition. I guess we
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Set the mask as right shift of integer by 31 (assuming integers are stored as two’s-complement 32-bit values and that the right-shift operator does sign extension).
XOR the mask with number
Subtract mask from result of step 2 and return the result.