# Variable type while creating a block

**URL:** <https://www.ruby-forum.com/t/variable-type-while-creating-a-block/242343>\
**Category:** GNU Radio\
**Created:** [June 16, 2015, 11:41pm UTC](https://www.ruby-forum.com/t/variable-type-while-creating-a-block/242343 "2015-06-16T23:41:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [June 16, 2015, 11:41pm UTC](https://www.ruby-forum.com/t/variable-type-while-creating-a-block/242343/1 "2015-06-16T23:41:32Z")

</div>

Hello

If i set the input of my block as a byte, means that the block will  
handle 8  
bits at a time and each item correspond to one bit of that byte?

in[0] is the first bit and so on?

Thank you.

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/variable-type-while-creating-a-block-tp54226.html](http://gnuradio.4.n7.nabble.com/variable-type-while-creating-a-block-tp54226.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Marbellys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc348/32.png) [@Marbellys](https://www.ruby-forum.com/u/Marbellys)\
**Post date:** [June 17, 2015, 1:20am UTC](https://www.ruby-forum.com/t/variable-type-while-creating-a-block/242343/2 "2015-06-17T01:20:16Z")

</div>

On Tue, Jun 16, 2015 at 2:17 PM, Marbellys  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> If i set the input of my block as a byte, means that the block will handle  
> 8  
> bits at a time and each item correspond to one bit of that byte?
> 
> in[0] is the first bit and so on?

No, this isn’t automatic. You would also have to precede your block  
with a  
block like gr::blocks::unpack\_k\_bits\_bb or ::repack\_k\_bits\_bb to  
generate  
such a stream from a packed byte format.

---

<div class="post-metadata">

**Author:** ![Marbellys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc348/32.png) [@Marbellys](https://www.ruby-forum.com/u/Marbellys)\
**Post date:** [June 17, 2015, 1:36am UTC](https://www.ruby-forum.com/t/variable-type-while-creating-a-block/242343/3 "2015-06-17T01:36:38Z")

</div>

Thank you, Johnathan.

So if i use an unpack\_k\_bits block, and i set k to 1, will I be handle  
1  
bit at a time?

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/variable-type-while-creating-a-block-tp54226p54229.html](http://gnuradio.4.n7.nabble.com/variable-type-while-creating-a-block-tp54226p54229.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Marbellys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc348/32.png) [@Marbellys](https://www.ruby-forum.com/u/Marbellys)\
**Post date:** [June 17, 2015, 4:06am UTC](https://www.ruby-forum.com/t/variable-type-while-creating-a-block/242343/4 "2015-06-17T04:06:11Z")

</div>

On Tue, Jun 16, 2015 at 4:13 PM, Marbellys  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> So if i use an unpack\_k\_bits block, and i set k to 1, will I be handle 1  
> bit at a time?

Yes.

---

<div class="post-metadata">

**Author:** ![Marbellys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc348/32.png) [@Marbellys](https://www.ruby-forum.com/u/Marbellys)\
**Post date:** [June 17, 2015, 9:32am UTC](https://www.ruby-forum.com/t/variable-type-while-creating-a-block/242343/5 "2015-06-17T09:32:14Z")

</div>

Dear Marbelly,

unpack\_k\_bits with k = 1 means, for instance,  
a byte sample 0x0F (0b0000 1111) in a stream  
is unpacked to 0x00 0x00 0x00 0x00 0x01 0x01 0x01 0x01 (MSB first)  
and only the first insignificant sample is taken and the rest 7 samples  
are  
discarded.

So if you want to process 8 bits in a byte individually, use  
unpack\_k\_bits  
with k = 8.

Regards,  
Jeon.

2015-06-17 11:49 GMT+09:00 Marbellys [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Marbellys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc348/32.png) [@Marbellys](https://www.ruby-forum.com/u/Marbellys)\
**Post date:** [June 17, 2015, 11:56pm UTC](https://www.ruby-forum.com/t/variable-type-while-creating-a-block/242343/6 "2015-06-17T23:56:51Z")

</div>

Hi Jeon.

Thank you very much for your response.

So if I have for example a vector source V =  
(1,1,0,1,0,0,1,0,0,0,1,0,1,1,0,1 (which output’s type is set to byte),  
the  
first stream at the output will be (1,1,0,1,0,0,1,0), is this right?  
Then, if I use an unpack\_k\_bits with k = 8 at its output, will I be able  
to  
save each of this bits in a vector in a new block and to manipulated  
them  
individually?

Thank you.  
Marbellys.

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/variable-type-while-creating-a-block-tp54226p54253.html](http://gnuradio.4.n7.nabble.com/variable-type-while-creating-a-block-tp54226p54253.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Marbellys](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc348/32.png) [@Marbellys](https://www.ruby-forum.com/u/Marbellys)\
**Post date:** [June 17, 2015, 5:13am UTC](https://www.ruby-forum.com/t/variable-type-while-creating-a-block/242343/7 "2015-06-17T05:13:26Z")

</div>

Thank you.

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/variable-type-while-creating-a-block-tp54226p54232.html](http://gnuradio.4.n7.nabble.com/variable-type-while-creating-a-block-tp54226p54232.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).
