Ready-to-run snippets

Code Examples

Ready-to-run Verilog, SystemVerilog, and UVM examples. Click any to open it live in the IDE.

← All examples

Bitwise Operators

Verilog Operators

Bitwise operators like &, |

Open in IDE
design.v
module des;
    reg data1 [4];
    reg data2 [4];
    int i, j;

    initial begin
        // Initialize test values: 0, 1, x, z
        data1[0] = 0; data2[0] = 0;
        data1[1] = 1; data2[1] = 1;
        data1[2] = 'x; data2[2] = 'x;
        data1[3] = 'z; data2[3] = 'z;

        // Test bitwise AND across all combinations
        for (i = 0; i < 4; i += 1) begin
            for (j = 0; j < 4; j += 1) begin
                $display ("data1(%0d) & data2(%0d) = %0d", data1[i], data2[j], data1[i] & data2[j]);
            end
        end
    end
endmodule
testbench.v
// Enter testbench code
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.