Skip to content

Instantly share code, notes, and snippets.

@logbasex
Created June 7, 2020 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save logbasex/582057188c264e8e6437b3ebf34bb114 to your computer and use it in GitHub Desktop.
Save logbasex/582057188c264e8e6437b3ebf34bb114 to your computer and use it in GitHub Desktop.
.
public static int getLargerNumber(int a, int b) {
int c = a - b;
//get sign bit's value
int k = (c >> 31) & 0x1;
return a - k * c;
}
public static void main(String[] args) {
//--------------------------------
int[] seq = new int[]{0, 3, 2, 6, 20, 5, 4};
int max = 0;
for (Integer i : seq) {
max = getLargerNumber(i, max);
}
System.out.println(max);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment