# Unary operator evaluation

Sherry Jacob
Ranch Hand
Posts: 128
Hi every1
Can any1 tell me how are these statements evaluated ?

They are unary operators. So how is the calculation being done ?

Steve Morrow
Ranch Hand
Posts: 657
It may help to understand that those are not unary operators; they're binary (left and right operands). They are evaluated left-to-right in order of precedence (accounting for parentheses, of course).

Steve Morrow
Ranch Hand
Posts: 657
P.S. The unary operators are +, -, ++, --, ~, !, and cast operators.

Examples:

Sherry Jacob
Ranch Hand
Posts: 128
I'm sorry I mentioned unary by mistake.

I meant Bitwise logical operators.

Thanks for pointing that out.

So how is it evaluated anyway ?

santhoshkumar samala
Ranch Hand
Posts: 156
The code is evaluated is as follows:

The numbers converted into the binary format and the opertaors on the binary format.

int a = 1 | 2 ^ 3 & 5;
The operation will be like this 001|010^011&101

The precedence is like this &,^,|

so the steps to the result are

1)001|010^001
2)001|011
3)011

The result is 3