# Extend value to vector size in SV

**URL:** <https://verificationacademy.com/forums/t/extend-value-to-vector-size-in-sv/33021>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, systemverilog-Arrays\
**Created:** [April 5, 2017, 12:11pm UTC](https://verificationacademy.com/forums/t/extend-value-to-vector-size-in-sv/33021 "2017-04-05T12:11:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefaniecg](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/d6d6ee/32.png) [@stefaniecg](https://verificationacademy.com/forums/u/stefaniecg)\
**Post date:** [April 5, 2017, 12:11pm UTC](https://verificationacademy.com/forums/t/extend-value-to-vector-size-in-sv/33021/1 "2017-04-05T12:11:20Z")

</div>

A little help with the syntax please:

I have a vector of a parameterizable size and I want to assign a value that extends to the size of the vector. The line I want to change is this one: **vector \<= 20;** in the following code:

```verilog

parameter int c_vector_bw = 5;
var logic [c_vector_bw-1:0] vector;

always_ff @(posedge clk) begin: p_vector
    if (vector_ld)
        vector <= 20;
    else
        vector <= '{default:'0};
    end
end: p_vector

```

I would like to write something like:

```verilog
vector <= $size(20,c_vector_bw);

```

but the previous doesn’t do what I want.

The idea is to do something like the VHDL function:

```vhdl

function RESIZE (ARG: SIGNED; NEW_SIZE: NATURAL) return SIGNED;
vector <= $resize(20,c_vector_bw);

```

How do I do that in SystemVerilog?

Thank you for the help you can provide!

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [April 5, 2017, 1:13pm UTC](https://verificationacademy.com/forums/t/extend-value-to-vector-size-in-sv/33021/2 "2017-04-05T13:13:46Z")

</div>

_In reply to [stefaniecg](https://verificationacademy.com/forums/t/extend-value-to-vector-size-in-sv/33021):_

First of all, there is no need to do this in Verilog/SystemVerilog - all vectors are implicitly extended or truncated to fit into the needed context.

But SystemVerilog has a cast operator that can be used to explicitly show your intent, or to change the context if it does not match what you want.

You can do

```verilog
 P'(expression). // changes the width of the expression to match the constant P
                        // - signedness remains the same 
 signed'(expression) // changes the signedness of an expression
 unsigned'(expression) // - width remains the same
 typename'(expression) // changes the width and signedness to match a user defined typename
                         // can also be used to reshape arrays and structs.

```

---

<div class="post-metadata">

**Author:** ![stefaniecg](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/d6d6ee/32.png) [@stefaniecg](https://verificationacademy.com/forums/u/stefaniecg)\
**Post date:** [April 6, 2017, 6:57am UTC](https://verificationacademy.com/forums/t/extend-value-to-vector-size-in-sv/33021/3 "2017-04-06T06:57:24Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/extend-value-to-vector-size-in-sv/33021/2):_

Thank you for drooping some knowledge!
