Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class BitShift {
- private static final Scanner input = new Scanner(System.in);
- public static void main(String[] args) {
- System.out.println(
- "Digite 1 para 'shiftToLeft' de inteiro, 2 para 'shiftToRight' de inteiro, "
- + System.lineSeparator()
- + "3 para 'shiftToLeft' de byte, 4 para 'shiftToRight' de byte ou qualquer outro para parar: "
- );
- Integer option = input.nextInt();
- do {
- switch (option) {
- case 1:
- shiftToLeftInteger();
- break;
- case 2:
- shiftToRightInteger();
- break;
- case 3:
- shiftToLeftByte();
- break;
- case 4:
- shiftToRightByte();
- break;
- default:
- break;
- }
- } while(option > 0 && option < 5);
- }
- public static void shiftToLeftInteger() {
- long value = 100000000;
- while(true) {
- System.out.println(value);
- value = value << 1;
- }
- }
- public static void shiftToRightInteger() {
- long value = 1;
- while(true) {
- System.out.println(value);
- value = value >> 1;
- }
- }
- public static void shiftToLeftByte() {
- byte value = (byte) 1;
- while(true) {
- System.out.println(value);
- value = (byte) (value << 1);
- }
- }
- public static void shiftToRightByte() {
- byte value = (byte) 64;
- while(true) {
- System.out.println(value);
- value = (byte) (value >> 1);
- }
- }
- }
Add Comment
Please, Sign In to add comment