# Bit conversion using streaming operator

**URL:** <https://verificationacademy.com/forums/t/bit-conversion-using-streaming-operator/38833>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, Streaming-Operator\
**Created:** [March 14, 2021, 2:30pm UTC](https://verificationacademy.com/forums/t/bit-conversion-using-streaming-operator/38833 "2021-03-14T14:30:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bachan21](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/bachan21/32/1208_2.png) [@bachan21](https://verificationacademy.com/forums/u/bachan21)\
**Post date:** [March 14, 2021, 2:30pm UTC](https://verificationacademy.com/forums/t/bit-conversion-using-streaming-operator/38833/1 "2021-03-14T14:30:13Z")

</div>

I am told to do bit conversion using streaming operator.  
I have a packet of 20 bits in size from a module and it must be packed to 32 bits packet while going from the module(Not zero padding)  
How can I solve this issue using streaming operator?

---

<div class="post-metadata">

**Author:** ![Desam](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/d/e56c9b/32.png) [@Desam](https://verificationacademy.com/forums/u/Desam)\
**Post date:** [March 15, 2021, 5:24pm UTC](https://verificationacademy.com/forums/t/bit-conversion-using-streaming-operator/38833/2 "2021-03-15T17:24:20Z")

</div>

_In reply to [bachan21](https://verificationacademy.com/forums/t/bit-conversion-using-streaming-operator/38833):_

I don’t think i understand your question properly…

but based on my understanding

```verilog
module dut_tb;
    typedef struct {
      bit [7:0] addr;
      bit [7:0] data;
    } packet_in;
    logic [31:0] combined_data; 
   initial begin
      packet_in p_in;
      p_in.addr = 10'hAB;
      p_in.data = 10'hCD;
   
     combined_data = { { >>{p_in.addr,p_in.data} } };
     $display("data = %0h",combined_data);    
   end 
endmodule

```

---

<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:** [March 15, 2021, 9:43pm UTC](https://verificationacademy.com/forums/t/bit-conversion-using-streaming-operator/38833/3 "2021-03-15T21:43:34Z")

</div>

_In reply to [bachan21](https://verificationacademy.com/forums/t/bit-conversion-using-streaming-operator/38833/2):_

I don’t understand your question either. Where are the extra 12 bits supposed to come from? Try explaining wha the code would like like without using the streaming operator.

---

<div class="post-metadata">

**Author:** ![bachan21](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/bachan21/32/1208_2.png) [@bachan21](https://verificationacademy.com/forums/u/bachan21)\
**Post date:** [March 16, 2021, 4:18am UTC](https://verificationacademy.com/forums/t/bit-conversion-using-streaming-operator/38833/4 "2021-03-16T04:18:00Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/bit-conversion-using-streaming-operator/38833/3):_

Hi Dave,

I am getting 20 bits packet from _sdi_ module and that packet will be used in _aximm_ after converting to 32 bits. I want to implement this logic in my TB scoreboard.

Let me elaborate my scoreboard logic with 8 bits and 16 bit data(for the simplicity of briefing) instead of 20 and 32 bits data packets. I am storing the 8 bit value into an array and that will be converted into an array of 16 bit values.

Lets assume an array of 8 bits in hex.

```verilog
A8 = '{'h05, 'h1a, 'h46, 'had, 'h19, 'ha9}

```

And 16 bit converted array after streaming will be

```verilog
B16 = '{'h051a, 'h46ad, 'h19a9}

```

This is the way I want my logic to be, but with 20 bits and 32 bits instead of 8 and 16 bits respectively  
How can put this into a systemverilog code
