Sign Extension
beginner · combinational · 50 XP
Sign in to write your solution, run it in the simulator and submit it for grading.
Sign in or create a free account →Problem
Sign Extension
Input: 8-bit signed number `in[7:0]`. Output: 16-bit sign-extended `out[15:0]`.
The upper 8 bits must replicate the MSB (sign bit):
```
out = {{8{in[7]}}, in[7:0]}
```
**Why this matters:** Every processor sign-extends when promoting 8-bit values to 16-bit or 32-bit arithmetic. Without sign extension, negative numbers become positive.
**Examples:**
- `in=8'h7F (+127) → out=16'h007F`
- `in=8'hFF (-1) → out=16'hFFFF`
- `in=8'h80 (-128) → out=16'hFF80`
Constraints
- Use the replication operator {N{bit}} for the upper byte.
Examples
Input: in=8'h7F
Output: out=16'h007F
Input: in=8'hFF
Output: out=16'hFFFF
Common questions
- What does the Sign Extension problem ask you to build?
- Sign Extension Input: 8-bit signed number `in[7:0]`. Output: 16-bit sign-extended `out[15:0]`. The upper 8 bits must replicate the MSB (sign bit): ``` out = {{8{in[7]}}, in[7:0]} ``` **Why this matters:** Every processor sign-extends when promoting 8-bit values to 16-bit or 32-bit arithmetic.
- What constraints does Sign Extension have?
- Use the replication operator {N{bit}} for the upper byte.
- What is an example input and output for Sign Extension?
- Input in=8'h7F gives output out=16'h007F.
- Which Verilog concepts does Sign Extension practise?
- combinational, vectors, replication, interview.