/**************************  Ganzzahl.java  ***********************************/

import AlgoTools.IO;

/**  Typumwandlung und Bitoperationen auf ganzen Zahlen 
 */
 
public class Ganzzahl {

  public static void main (String [] argv) {

    byte b;                               // ganze Zahl mit  8 Bit
    int  n;                               // ganze Zahl mit 32 Bit
 
    b = -127;                             // setze b auf -127;
    n = b;                                // implizite Typumwandlung
                                          // n hat nun den Wert -127
                                          // codiert auf 4 Bytes
 
    n = 130;                              // setze n auf 130 
    b = (byte) n;                         // explizite Typumwandlung       
    IO.println(b);                        // b hat nun den Wert -126
                                          // codiert auf einem Byte 
 
    n = -2 ;                              // setze n auf -2 
    b = (byte) n;                         // explizite Typumwandlung       
    IO.println(b);                        // b hat nun den Wert -2
                                          // codiert auf einem Byte 
 
    n = 1;                                // initialisiere n
    while (n > 0) {                       // solange n positiv ist
        n = n * 10;                       // verzehnfache n
        IO.println(n, 20);                // drucke n auf 20 Stellen
    }                                     // letzter Wert ist negativ ! 

    byte x=-127, y=126;
                                          // Obacht: jeweils cast auf int ! 
    IO.println( x & y  );                 // bitweise Und-Verknuepfung
    IO.println( x | y  );                 // bitweise Oder-Verknuepfung
    IO.println( x ^ y  );                 // bitweise XOR-Verknuepfung
    IO.println( ~x     );                 // bitweise Negation
    IO.println( x <<  6);                 // Linksshift 
    IO.println( x >>  6);                 // Vorzeichen erhalt. Rechtsshift
    IO.println( x >>> 6);                 // Vorzeichen ignor.  Rechtsshift
  }                                       // d.h. Nullen nachschieben
}
