|
|
|
|
|
|
|
|
|
|
|
|
Bitwise Operators
|
|
|
The bit-wise operators operate on each bit from the same bit position of the operands and return a 1 bit value. If the sizes of the operands are not the same, the higher order bits of the smaller size operands are filled with 0's before an operation. |
|
|
|
|
|
Following are the bit wise operators supported in VERA. |
|
|
|
|
|
- ~ : Inversion Operation
- | : OR Operation
- & : AND Operation
- ^ : XOR Operation
|
|
|
|
|
|
- Computations include unknown bits, in the following way:
- ~x = x
- 0&x = 0
- 1&x = x&x = x
- 1|x = 1
- 0|x = x|x = x
- 0^x = 1^x = x^x = x
- 0^~x = 1^~x = x^~x = x
- When operands are of unequal bit length, the shorter operand is zero-filled in the most significant bit positions.
|
|
|
|
|
|
Following are the result of bitwise operation on various values. |
|
|
|
|
|
Inversion |
|
|
|
|
|
|
|
|
|
|
|
AND |
|
|
|
|
|
&
|
0
|
1
|
X
|
Z
|
0
|
0
|
0
|
0
|
0
|
1
|
0
|
1
|
x
|
x
|
x
|
0
|
x
|
x
|
x
|
z
|
0
|
x
|
x
|
x
|
|
|
|
|
|
|
OR |
|
|
|
|
|
|
|
0
|
1
|
x
|
z
|
0
|
0
|
1
|
x
|
x
|
1
|
1
|
1
|
1
|
1
|
x
|
x
|
1
|
x
|
x
|
z
|
x
|
1
|
x
|
x
|
|
|
|
|
|
|
XOR |
|
|
|
|
|
^
|
0
|
1
|
x
|
z
|
0
|
0
|
1
|
x
|
x
|
1
|
1
|
0
|
x
|
x
|
x
|
x
|
x
|
x
|
x
|
z
|
x
|
x
|
x
|
x
|
|
|
|
|
|
|
|
|
|
|
|
|
Example : Bitwise Operators
|
|
|
|
|
|
1 program bitwise {
2 bit [7:0] data = 8'hA0;
3 bit [7:0] addr = 8'hA5;
4 bit [15:0] mem_addr = 16'h1234;
5 integer i = 32'hDEAD_BEEF;
6 bit [7:0] result = 0;
7 // Bitwise inversion
8 printf("Inversion of %b is %b\n",data, ~data);
9 // Bitwise AND
10 printf("AND of %b with %b is %b\n",data, addr,data & addr);
11 // Bitwise OR
12 printf("OR of %b with %b is %b\n",data, addr,data | addr);
13 // Bitwise XOR
14 printf("XOR of %b with %b is %b\n",data, addr,data ^ addr);
15 // Bitwise operation on integer and bit
16 result = i | data;
17 printf("OR of %b with %b is %b\n",data, i,result);
18 // Bitwise operation on different width operands
19 mem_addr = data ^ i;
20 printf("XOR of %b with %b is %b\n",data, i,mem_addr);
21 }
You could download file bitwise.vr here
|
|
|
|
|
|
Simulation : Bitwise Operators
|
|
|
|
|
|
Inversion of 10100000 is 01011111
AND of 10100000 with 10100101 is 10100000
OR of 10100000 with 10100101 is 10100101
XOR of 10100000 with 10100101 is 00000101
OR of 10100000 with 11011110101011011011111011101111 is 11101111
XOR of 10100000 with 11011110101011011011111011101111 is 1011111001001111
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|