Skip to content

Instantly share code, notes, and snippets.

@rayjcwu
Created April 15, 2014 21:56
Show Gist options
  • Save rayjcwu/10780724 to your computer and use it in GitHub Desktop.
Save rayjcwu/10780724 to your computer and use it in GitHub Desktop.
public boolean lastIsSingleByteChar(byte[] bytes) {
final int N = bytes.length;
if (N == 0) {
throw new IllegalArgumentException();
}
if (N == 1) {
return true;
}
int i = N - 1;
if (isZero(bytes[i]) && isZero(bytes[i - 1])) {
return true;
}
i--;
while (i >= 0 && isOne(bytes[i])) {
i--;
}
return (N - i - 1) % 2 != 0;
}
public boolean isZero(byte b) {
return (b>>7) == 0;
}
public boolean isOne(byte b) {
return (b>>7) == 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment