Sunday, June 12, 2011

JAVA : Integer Operator Java


download materi integer operator

operating binary integer operator on integer couple. Following is binary integer operator table.














Deskripsi
Operator
Increase
+
Cut back
-
multiple
*
division
/
Rest for
%
Bitwise AND
&
Bitwise OR
|
Bitwise XOR
^
Left-shift
<< 
Right-shift
>> 
Zero-fill-right-shift
>>> 

sum operator, cut back, multiple, and division(+, -, *, /) doing operation as on aritmatika integer.

Highlight that needs at cermati is make the point division operator work with integer transfer. Division operator transfer integer quotient. If division results rest for therefore modulus operator(%) can at utilizes to get rest point for that.

Following is program Arithmetic to point out aritmatika's operator job binary:




Arithmatic.java
package arithmatic;

public class Arithmatic {
   public static void main (String args[]) {
       int x = 17, y = 5;

       System.out.println(“x =” + x);
       System.out.println(“y =” + y);
       System.out.println(“x + y” + (x+y));
       System.out.println(“x - y” + (x-y));
       System.out.println(“x * y” + (x*y));
       System.out.println(“x / y” + (x/y));
       System.out.println(“x % y” + (x%y));
   }
}


Instruction:

javac Arithmetic.java
Arithmetic's Java

Result Programs:

x = 17
y. = 5
x + y. = 22
x y. = 12
x * y. = 85
x / y. = 3
x % y. = 2

Quotient x / y. which is 17 / 5 results 3. modulus Operation x % y. which is 17 % 5 result 2 (which is rest for integer).

matenatika's ala division with zero don't at defines. Java treats this division by throws / result runtime exeception. We will study exeception alone ala.

bitwise AND's operator, OR, and XOR

bitwise and's operator, or, and xor(&, |, and ^) act on individual bit bit integer. This operator sometime beneficent while integers that at utilizes as field's bit.

example:
Number purpose as field's bit is subject to be declaration a group flag binary number. One number int that mempresentasikan can until 32 flag that different because int at deep keeping 32 bits.




Bitwise.java
package bitwise;

public class Bitwise {
   public static void main (String args[]) {
       Int x = 5, y = 6;
       System.out.println(“x =” + x);
       System.out.println(“y =” + y);
       System.out.println(“x & y” + (x&y));
       System.out.println(“x | y” + (x|y));
       System.out.println(“x ^ y” + (x^y));
  }
}


Instruction:

javac Bitwise
Bitwise's Java

Result programs:

x = 5
y. = 6
x & y. = 4
x | y. = 7
x ^ y. = 3

To understand output result, we shall understand representasi int's number in two' s complement.

Shift operator
Looking at samples following:

x<< 3;
y.>> 7;
z.>>> 2;

On first example, variable individual bit bit integer x is angled to left as much three positions. On second example, bit bit of y. at angles to right as much position sevens. On example drding to point out z. at angles as much 2 positions, with give duck's egg on two left utmost positions.

Looking at programs following:




Shift.java
package shift;

public class Shift {
   Public static void main (String args[]){
       Int x = 7;
       System.out.println(“x =” + x);
       System.out.println(“x >> 2 =” + (x >>> 2));
       System.out.println(“x << 1 =” + (x << 1));
       System.out.println(“x >>> 1 =” + (x >>> 1));
   }
}


Instruction:

javac Shift.java
Shift Java

Result Programs:

x = 7
x>> 2 = 1
x<< 1 = 14
x>>> 1 = 3
download  materi integer operator

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More