Справочник по Java/Java-Shildt-100BitLogic

Java-Shildt-100BitLogic


{{Готовность|0%}}

Содержание
  • Java-Shildt-100BitLogic
  • Java-Shildt-102ByteShift
  • Java-Shildt-102MultByTwo
  • Java-Shildt-104HexByte
  • Java-Shildt-105ByteUShift
  • Java-Shildt-106OpBitEquals
  • Java-Shildt-108BoolLogic
  • Java-Shildt-110Ternary
  • Java-Shildt-116IfElse
  • Java-Shildt-117SampleSwitch
  • Java-Shildt-130ForEach2
  • Java-Shildt-133Nested
  • Java-Shildt-143BoxDemo
  • Java-Shildt-143BoxDemo2
  • Java-Shildt-149BoxDemo3
  • Java-Shildt-150BoxDemo4
  • Java-Shildt-152BoxDemo5
  • Java-Shildt-154BoxDemo6
  • Java-Shildt-155BoxDemo7
  • Java-Shildt-159Stack
  • Java-Shildt-160TestStack
  • Java-Shildt-161Overload
  • Java-Shildt-162Overload2
  • Java-Shildt-164Box
  • Java-Shildt-165OverloadCons
  • Java-Shildt-166PassOb
  • Java-Shildt-167OverloadCons2
  • Java-Shildt-168CallByValue
  • Java-Shildt-169CallByRef
  • Java-Shildt-169RetOb
  • Java-Shildt-170Recursion
  • Java-Shildt-172Recursion2
  • Java-Shildt-173AccessTest
  • Java-Shildt-174Stack
  • Java-Shildt-175TestStack
  • Java-Shildt-176UseStatic
  • Java-Shildt-177StaticByName
  • Java-Shildt-178Length
  • Java-Shildt-178TestStack2
  • Java-Shildt-180InnerClassDemo
  • Java-Shildt-180InnerClassDemo2
  • Java-Shildt-181InnerClassDemo3
  • Java-Shildt-182StringDemo
  • Java-Shildt-183StringDemo2
  • Java-Shildt-184CommandLine
  • Java-Shildt-184StringDemo3
  • Java-Shildt-185PassArray
  • Java-Shildt-186VarArgs
  • Java-Shildt-187VarArgs2
  • Java-Shildt-187VarArgs3
  • Java-Shildt-188VarArgs4
  • Java-Shildt-191SimpleInheritance
  • Java-Shildt-193Access
  • Java-Shildt-194DemoBoxWeight
  • Java-Shildt-195ColorBox
  • Java-Shildt-195RefDemo
  • Java-Shildt-197BoxWeight
  • Java-Shildt-197DemoSuper
  • Java-Shildt-200UseSuper
  • Java-Shildt-70Light
  • Java-Shildt-71Area
  • Java-Shildt-72CharDemo
  • Java-Shildt-72CharDemo2
  • Java-Shildt-77DynInit
  • Java-Shildt-87TwoDArray
  • Java-Shildt-89Matrix
  • Java-Shildt-89ThreeDMatrix
  • Java-Shildt-94BasicMath
  • Java-Shildt-96OpEquals
  • Java-Shildt-97IncDec
  • Java-Shildt-Example
  • Java-Shildt-Example2
  • Java-Shildt-ForTest
  • Java-Shildt-IfSample

Полный справочник по Java. Java SE 6 Edition. 7-е издание. Герберт Шилдт. "Вильямс", Москва - Санкт-Петербург - Киев, 2007, стр.100.

// 100
// Демонстрация побитовых логических операций.
public class BitLogic  {
   public static void main(String args[])  {
      String binary[] = {
         "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111",
         "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"
      };   
      int a = 3; // 0 + 2 + 1 или 0011 в двоичном представлении
      int b = 6; // 4 + 2 + 0 или 0110 в двоичном представлении
      int c = a | b;
      int d = a & b;
      int e = a ^ b;
      int f = (~a & b) | (a & ~b);
      int g = ~a & 0x0f;      
      System.out.println("a = " + binary[a]);
      System.out.println("b = " + binary[b]);
      System.out.println("a|b = " + binary[c]);
      System.out.println("a&b = " + binary[d]);
      System.out.println("a^b = " + binary[e]);
      System.out.println("~a&b|a&~b = " + binary[f]);
      System.out.println("~a = " + binary[g]);
    }
}