Operator Introduction

Operator Introduction

Operator

Operand

C = A+B → Binary ada + =

  • % (modulus)

*

/

 

Operation number 3 :

Unary Operator → 1 operand

Binary Operator → 2 operand

Temary Operand → 3 operand

Operation type 6 group :

  • Assignment → nilai variabel X = 3 (operand 1 = operand 2)
  • Logical
  • Arithmetic → + − * / % ++ −− ()
  • Relational
  • Bitwise
  • Pointer

 

N ++ : // post increament

+ NN : // pre increament

N −−  : // post decreament

−− N : // pre decrement

 

Expression                            combined operator

A = a + b;                               a + = b;

A = a – b;                               a – = b;

 

Relational

= =   → Equality

! =    → Not Equal

<      → Less than

>      → Greater than

< =   → Less or equal then

> =   → Greath or equal then

? =   → Conditional statement

1 = T   X = ( 20 > 10 ) ; (1)

0 = f    X = ( 20 > 10 ) ; (1)

 

Conditional expressions

If ( a > b ) Z = a;

Else Z = b ;

Z = ( a > b ) ? a : b ;

A = 5                 Z = 3                           benar               Z = a

B = 3                                                     salah         Z≠ b

A = 3                Z =7

B = 5

 

Logical Operator

Symbol Functionally
&& AND
|| OR
| NOT

 

P Q Xor → a|b & ! (a & b)
T T F
T F T
F T T
F F F

 

Logical operators

Int X = 5 , int Y = 0 ;

X && Y;                        // FALSE               0

(X > Y ) && ( Y >= 0 )   // TRUE ≠ 0

 

Bitwise

Symbol Meaning Example
& AND A & B
| OR A|B;
˄ XOR A˄B;
˜ Complement ˜A;
>> Shiftt right A>>3;
<< Shift left B<<2,

 

EX:

10 : itu berapa bit

Cari 2n yang lebih kecil dari 10
n = 3

23      22     21    20

_      _     _     _

 

15 itu berapa bit

23  :  ˄ = 3

1       1     1     1

__   __   __   __

15 – 8 = 7 = 23 = 3 – 21  = 1

 

37 = 25

1      0      0      1      0    1

__    __   __   __   __   __                                                  37 – 25  = 5 – 22 = 1- 20 = 0

25   24   222 220                 

I I = ( 100 – 1 )

I I I = ( 1000 – 1 )

I I I I I I = 63

( 100000 ) – 1

64 -1 = 63

 

Bit wise = yang dioperasikan Bitnya

4 = 100                4 = 100

3 = 011               5 = 011

0 = 000               1 = 111

int A,B = 78

A = B >> 3 ; // Value A = 9

A = B << 2 ; // Value A = 312

78, binary : 0100 1110

First shift      : 0010 0111

Second shift : 0001 0011

Third shift     : 0000 1001               9 decimal

Operator Introduction

Operator

Operand

C = A+B → Binary ada + =

  • % (modulus)

*

/

 

Operation number 3 :

Unary Operator → 1 operand

Binary Operator → 2 operand

Temary Operand → 3 operand

Operation type 6 group :

  • Assignment → nilai variabel X = 3 (operand 1 = operand 2)
  • Logical
  • Arithmetic → + − * / % ++ −− ()
  • Relational
  • Bitwise
  • Pointer

 

N ++ : // post increament

+ NN : // pre increament

N −−  : // post decreament

−− N : // pre decrement

 

Expression                            combined operator

A = a + b;                               a + = b;

A = a – b;                               a – = b;

 

Relational

= =   → Equality

! =    → Not Equal

<      → Less than

>      → Greater than

< =   → Less or equal then

> =   → Greath or equal then

? =   → Conditional statement

1 = T   X = ( 20 > 10 ) ; (1)

0 = f    X = ( 20 > 10 ) ; (1)

 

Conditional expressions

If ( a > b ) Z = a;

Else Z = b ;

Z = ( a > b ) ? a : b ;

A = 5                 Z = 3                           benar               Z = a

B = 3                                                     salah         Z≠ b

A = 3                Z =7

B = 5

 

Logical Operator

Symbol Functionally
&& AND
|| OR
| NOT

 

P Q Xor → a|b & ! (a & b)
T T F
T F T
F T T
F F F

 

Logical operators

Int X = 5 , int Y = 0 ;

X && Y;                        // FALSE               0

(X > Y ) && ( Y >= 0 )   // TRUE ≠ 0

 

Bitwise

Symbol Meaning Example
& AND A & B
| OR A|B;
˄ XOR A˄B;
˜ Complement ˜A;
>> Shiftt right A>>3;
<< Shift left B<<2,

 

EX:

10 : itu berapa bit

Cari 2n yang lebih kecil dari 10
n = 3

23      22     21    20

_      _     _     _

 

15 itu berapa bit

23  :  ˄ = 3

1       1     1     1

__   __   __   __

15 – 8 = 7 = 23 = 3 – 21  = 1

 

37 = 25

1      0      0      1      0    1

__    __   __   __   __   __                                                  37 – 25  = 5 – 22 = 1- 20 = 0

25   24   222 220                 

I I = ( 100 – 1 )

I I I = ( 1000 – 1 )

I I I I I I = 63

( 100000 ) – 1

64 -1 = 63

 

Bit wise = yang dioperasikan Bitnya

4 = 100                4 = 100

3 = 011               5 = 011

0 = 000               1 = 111

int A,B = 78

A = B >> 3 ; // Value A = 9

A = B << 2 ; // Value A = 312

78, binary : 0100 1110

First shift      : 0010 0111

Second shift : 0001 0011

Third shift     : 0000 1001               9 decimal

Leave a Reply

Your email address will not be published. Required fields are marked *