Find first and last set bit of a long integer: Difference between revisions

Content added Content deleted
Line 303: Line 303:


public static int mssb_idx(int x) {
public static int mssb_idx(int x) {
return 31 - Integer.numberOfLeadingZeros(x);
return Integer.SIZE - 1 - Integer.numberOfLeadingZeros(x);
}
}


public static int mssb_idx(long x) {
public static int mssb_idx(long x) {
return 63 - Long.numberOfLeadingZeros(x);
return Long.SIZE - 1 - Long.numberOfLeadingZeros(x);
}
}