Advertisement
Mancolo

Побитовые операции, логическое умножение, сложение, исключение

Feb 17th, 2021
1,430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.86 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         System.out.println("===Первое задание===");
  6.         int a = 8, b = 31, c = 45;
  7.         System.out.println(a +" Бинарное значение = " + Integer.toBinaryString(a));
  8.         System.out.println(b + " Бинарное значение = " + Integer.toBinaryString(b));
  9.         System.out.println(c + " Бинарное значение = " + Integer.toBinaryString(c));
  10.  
  11.         int num1 = a>>2;
  12.         int num2 = b>>2;
  13.         int num3 = c>>2;
  14.         System.out.println("========================");
  15.         System.out.println("Сдвиг направо:");
  16.  
  17.         System.out.println(num1 + " Бинарное значение = " + Integer.toBinaryString(num1));
  18.         System.out.println(num2 +" Бинарное значение = " + Integer.toBinaryString(num2));
  19.         System.out.println(num3 +" Бинарное значение = " + Integer.toBinaryString(num3));
  20.         int a1 = -18, b1 = -45, c1 = -51;
  21.         System.out.println("========================");
  22.         System.out.println(a1 +"  Бинарное значение = " + Integer.toBinaryString(a));
  23.         System.out.println(b1 +" Бинарное значение = " + Integer.toBinaryString(b));
  24.         System.out.println(c1 +" Бинарное значение = " + Integer.toBinaryString(c));
  25.         System.out.println("========================");
  26.         System.out.println("Сдвиг налево:");
  27.  
  28.         int num4 = a1>>3;
  29.         int num5 = b1>>3;
  30.         int num6 = c1>>3;
  31.  
  32.         System.out.println( num4 +" Бинарное значение = " + Integer.toBinaryString(num4));
  33.         System.out.println( num5 +" Бинарное значение = " + Integer.toBinaryString(num5));
  34.         System.out.println( num6 +" Бинарное значение = " + Integer.toBinaryString(num6));
  35.         System.out.println("==================");
  36.         System.out.println("Четвертое задание:");
  37.         System.out.println(-8 | 9);
  38.         System.out.println(-11 | 22);
  39.         System.out.println(-8 & 22);
  40.         System.out.println(-11 & 9);
  41.         System.out.println(-8 ^ -11);
  42.         System.out.println(9 ^ 22);
  43.         System.out.println("==================");
  44.         System.out.println("Пятое задание:");
  45.         int x = -22, y = 201;
  46.         byte x1 = (byte) a, y1= (byte) b;
  47.         double d = 22.98d;
  48.         int x2 = (int) d;
  49.         float f = 54.76f;
  50.         int x3= (int) f;
  51.         int r = 23123123;
  52.         float x4 = (float) r;
  53.         double d1 = 4.9734342d;
  54.         int x5 = (int) Math.round(d1);
  55.         System.out.println(x1);
  56.         System.out.println(y1);
  57.         System.out.println(x2);
  58.         System.out.println(x3);
  59.         System.out.println(x4);
  60.         System.out.println(x5);
  61.  
  62.  
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement