Skip to content

Instantly share code, notes, and snippets.

@cdleary
Created August 10, 2011 17:31
Show Gist options
  • Save cdleary/1137545 to your computer and use it in GitHub Desktop.
Save cdleary/1137545 to your computer and use it in GitHub Desktop.
Bitwise signedness
class Foo {
public static void main(String[] args) {
System.out.println("Number is less than zero: " + (0x80000000 < 0));
System.out.println("Self-bitwise-&: " + (0x80000000 & 0x80000000));
System.out.println("Self-bitwise-& is self: " + ((0x80000000 & 0x80000000) == 0x80000000));
}
}
/*
Number is less than zero: true
Self-bitwise-&: -2147483648
Self-bitwise-& is self: true
*/
print("Number is less than zero: " + (0x80000000 < 0));
print("Self-bitwise-&: " + (0x80000000 & 0x80000000));
print("Self-bitwise-& is self: " + ((0x80000000 & 0x80000000) == 0x80000000));
/*
Number is less than zero: false
Self-bitwise-&: -2147483648
Self-bitwise-& is self: false
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment