/* * [TestShift.java] * * Summary: Demonstrate the use of shift. * * Copyright: (c) 2011-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2011-04-27 initial version */ package com.mindprod.example; import static java.lang.System.*; /** * Demonstrate the use of shift. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2011-04-27 initial version * @since 2011-04-27 */ public final class TestShift { /** * Test harness * * @param args not used */ public static void main( String[] args ) { int i = -1; i = i >>> 32; out.println( i ); // i is -1, not 0 as you might expect, Equivalent to >>> 0. int j = 4; j = j >>> -1; out.println( j ); // j is 0, not 2 as you might expect. Equivalent to >>> 31 long k = 1; k = k << 65; out.println( k ); // k is 2, not 0 as you might expect. Equivalent to << 1 } }