Skip to content

Instantly share code, notes, and snippets.

@PeterZhukov
Last active June 26, 2020 16:48
Show Gist options
  • Select an option

  • Save PeterZhukov/e20970713e3187aa9879e1ae6a581f49 to your computer and use it in GitHub Desktop.

Select an option

Save PeterZhukov/e20970713e3187aa9879e1ae6a581f49 to your computer and use it in GitHub Desktop.
package com.example.helloworld;
public class Shift {
public static void showShift(){
//byte val = 1; int tmp;
byte val = (byte) (1 << 7); int tmp;
int r;
for(int i = 0; i < 32; i++){
tmp = val;
//tmp <<= i;
tmp >>= i;
for(long t = Integer.MAX_VALUE + 1L; t > 0; t /= 2){
if ((tmp & t) != 0) System.out.print("1 ");
else System.out.print("0 ");
}
r = tmp;
System.out.print("r: " + r + " (byte)r: " + (byte)r);
System.out.println();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment