Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*==================================================================================================
- --------------------------------------------------------------------------------------------------
- [BitwiseAND1.java]
- A thorough probe of the binary abyss: exploiting the logic that 'x' ANDed with 1 WILL ALWAYS
- yield a result of either 1, if 'x' is an odd number (having its lowest order bit set to 1),
- or 0, if 'x' is an even number (having its lowest order bit set to 0)...
- ...and the symbolic link between the aforementioned operation and: x % 2.
- (c) Damion 'Phr0z3n.dev' Tapper, 2014.
- Email: Phr0z3n.Dev@Gmail.com
- Website: http://L337Stuff.Blogspot.com
- --------------------------------------------------------------------------------------------------
- ==================================================================================================*/
- public class BitwiseAND1
- {
- public static void main(String arg[])
- {
- new BitwiseAND1();
- }
- BitwiseAND1()
- {
- for(int i = 0; i <= 10; i++)
- {
- System.out.print(i + " is an ");
- System.out.print( (i % 2 == 0) /* i AND 0 */ ? "even" : "odd" );
- System.out.print(" number. " + i + " AND (binay) 1 MUST be ");
- System.out.print( (i % 2 == 0) ? "0" : "1" ); // The new and improved conditional operator.
- System.out.println(": ");
- System.out.println(i + " & 1 = " + (i & 1));
- System.out.println(); // POSIX-friendly (\n is too selfish)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement