Created
March 11, 2015 15:12
-
-
Save mbchoa/415f1c98c8dd3bd0dbee to your computer and use it in GitHub Desktop.
Determine integer absolute value using bitwise operations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int abs(int value){ | |
int mask = value>>31; | |
return (value ^ mask) - mask; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment