Continue to Site

### Welcome to EDAboard.com

#### Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Status
Not open for further replies.

##### Junior Member level 3
Hi All, Please look below & help me.

Firstly,

if(temp^0b00000001)

In the above what is the work of '^' operator & how it's work?Please explain.

secondly,
derivative_term = derivative_term >> 5; // divide by 32 precalculated Kp*X*3*Ts.
In the above what is the work of '>>' operator & how it's work? Please explain.

Thirdly,
CCPR1L = Cn >> 2; // Used to stop the pendulum from continually going around in a circle
In the above what is the work of '>>' operator & how it's work? Please explain.

Firstly,

if(temp^0b00000001)

In the above what is the work of '^' operator & how it's work?
It's the logical AND operator, see here.

secondly,
derivative_term = derivative_term >> 5; // divide by 32 precalculated Kp*X*3*Ts.
In the above what is the work of '>>' operator & how it's work?
The logical shift right operator, >> 5 results in a divide by 25 = 32 operation.

Thirdly,
CCPR1L = Cn >> 2; // Used to stop the pendulum from continually going around in a circle
In the above what is the work of '>>' operator & how it's work?
Again, shift right (by 2), results in a divide by 22 = 4 operation.

Points: 2
I give full code below,

temp_int = abs(Cn); // Returns the absolute int value of Cn
temp = temp_int; // int to char of LS-Byte
if(temp^0b00000001){
DC1B0 = 1;
}

please give me example... to realize the meaning of "temp^0b00000001"

Thanks

please give me example... to realize the meaning of "temp^0b00000001"

simply a logical AND :

0bxxxxxxx1 ^ 0b00000001 = 0b00000001
0bxxxxxxx0 ^ 0b00000001 = 0b00000000

Points: 2
simply a logical AND :

0bxxxxxxx1 ^ 0b00000001 = 0b00000001
0bxxxxxxx0 ^ 0b00000001 = 0b00000000

^ is the XOR operation logical AND is &.

https://www.asic-world.com/verilog/operators1.html

- - - Updated - - -

I give full code below,

temp_int = abs(Cn); // Returns the absolute int value of Cn
temp = temp_int; // int to char of LS-Byte
if(temp^0b00000001){
DC1B0 = 1;
}

please give me example... to realize the meaning of "temp^0b00000001"

Thanks

I just noticed the { } braces...I guess this is C not Verilog...

^ in C is still bit-wise XOR and & is bit-wise AND.

Points: 2
^ is the XOR operation logical AND is &.

https://www.asic-world.com/verilog/operators1.html

- - - Updated - - -

I just noticed the { } braces...I guess this is C not Verilog...

^ in C is still bit-wise XOR and & is bit-wise AND.

You're right with Verilog and C, but it seems to be different for other languages: see the Wiki link given above.

Perhaps the OP Mizan.Bangladesh should tell us which program resp. language he is using.

Points: 2
Hi thanks to all,

i am using C programing language.

Now, please give me example... to realize the meaning of "temp^0b00000001"

Hi thanks to all,

i am using C programing language.

Now, please give me example... to realize the meaning of "temp^0b00000001"

Mizan: If you're writing programs in C language, you really should be able to find the result of the XOR operation yourself!
(The result is exactly the inverse of the AND operation shown above.)

Points: 2
You're right with Verilog and C, but it seems to be different for other languages:

The carret ^ isn't the same as the /\ (think of it as joined at the top ;-)) symbol which is the mathematical(?) AND symbol. I've never seen in any computer sw/hw language the use of ^ for AND, but then again I don't know all of them.

0bxxxxxxx1 ^ 0b00000001 = 0b00000001
0bxxxxxxx0 ^ 0b00000001 = 0b00000000

I don't think this would be valid in C. There is no X in C

The OP should understand the truth table of XOR:
0 0 | 0
0 1 | 1
1 0 | 1
1 1 | 0

This table is applied bit-wise for each pair of inputs, therefore:
temp^0b00000001, if temp is say 0b11110000

1 0 = 1
1 0 = 1
1 0 = 1
1 0 = 1
0 0 = 0
0 0 = 0
0 0 = 0
0 1 = 1