Prev Problem
Next Problem

45. Signed vs Unsigned Compare

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

 

 

Code

//==================================================
// Module: signed_thresh
// Description: Compares two 8-bit values — one as unsigned
// and one as signed (two’s complement).
//==================================================
module signed_thresh (
    input  wire [7:0] sample,
    input  wire [7:0] thresh,
    output wire       gt_unsigned,
    output wire       gt_signed
);

    // Unsigned comparison
    assign gt_unsigned = (sample > thresh);

    // Signed comparison (treat as 8-bit signed numbers)
    assign gt_signed = ($signed(sample) > $signed(thresh));

endmodule

 

Was this helpful?
Upvote
Downvote