Guest User

Untitled

a guest
Sep 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class BitShift {
  4. private static final Scanner input = new Scanner(System.in);
  5.  
  6. public static void main(String[] args) {
  7. System.out.println(
  8. "Digite 1 para 'shiftToLeft' de inteiro, 2 para 'shiftToRight' de inteiro, "
  9. + System.lineSeparator()
  10. + "3 para 'shiftToLeft' de byte, 4 para 'shiftToRight' de byte ou qualquer outro para parar: "
  11. );
  12. Integer option = input.nextInt();
  13.  
  14. do {
  15. switch (option) {
  16. case 1:
  17. shiftToLeftInteger();
  18. break;
  19. case 2:
  20. shiftToRightInteger();
  21. break;
  22. case 3:
  23. shiftToLeftByte();
  24. break;
  25. case 4:
  26. shiftToRightByte();
  27. break;
  28. default:
  29. break;
  30. }
  31. } while(option > 0 && option < 5);
  32. }
  33.  
  34. public static void shiftToLeftInteger() {
  35. long value = 100000000;
  36. while(true) {
  37. System.out.println(value);
  38.  
  39. value = value << 1;
  40. }
  41. }
  42.  
  43. public static void shiftToRightInteger() {
  44. long value = 1;
  45. while(true) {
  46. System.out.println(value);
  47.  
  48. value = value >> 1;
  49. }
  50. }
  51.  
  52. public static void shiftToLeftByte() {
  53. byte value = (byte) 1;
  54. while(true) {
  55. System.out.println(value);
  56.  
  57. value = (byte) (value << 1);
  58. }
  59. }
  60.  
  61. public static void shiftToRightByte() {
  62. byte value = (byte) 64;
  63. while(true) {
  64. System.out.println(value);
  65.  
  66. value = (byte) (value >> 1);
  67. }
  68. }
  69. }
Add Comment
Please, Sign In to add comment