# Operation of short to char

**URL:** <https://www.ruby-forum.com/t/operation-of-short-to-char/245684>\
**Category:** GNU Radio\
**Created:** [June 27, 2013, 8:35pm UTC](https://www.ruby-forum.com/t/operation-of-short-to-char/245684 "2013-06-27T20:35:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [June 27, 2013, 8:35pm UTC](https://www.ruby-forum.com/t/operation-of-short-to-char/245684/1 "2013-06-27T20:35:44Z")

</div>

Hi,

Just wondering if the operation of short to char is a bug or  
intentional.  
The most significant 8 bits of the short gets converted to char, ie:

0-255 (short) -\> 0 (char)  
256-511 (short) -\> 1 (char)  
512-767 (short) -\> 2 (char)

This is not the operation I expected, but the unit test allows it to  
work  
this way, so I am confused.

Regards,

Stephen

---

<div class="post-metadata">

**Author:** ![Stephen\_Harrison](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@Stephen\_Harrison](https://www.ruby-forum.com/u/Stephen_Harrison)\
**Post date:** [June 27, 2013, 9:09pm UTC](https://www.ruby-forum.com/t/operation-of-short-to-char/245684/2 "2013-06-27T21:09:37Z")

</div>

I think that I posted something similar few weeks ago. I also didn’t  
expect  
that 0-255 short goes to 0 char, and spent like a day trying to figure  
out  
the bug, but at the end it is like that.

On Thu, Jun 27, 2013 at 8:34 PM, Stephen Harrison

---

<div class="post-metadata">

**Author:** ![Stephen\_Harrison](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@Stephen\_Harrison](https://www.ruby-forum.com/u/Stephen_Harrison)\
**Post date:** [June 27, 2013, 9:14pm UTC](https://www.ruby-forum.com/t/operation-of-short-to-char/245684/3 "2013-06-27T21:14:53Z")

</div>

Oh, like the lower 8 bits are like additional precision “digits” that  
are being truncated… I would not have expected that either. Comments in  
the GRC XML file would be good…

From: discuss-gnuradio-bounces+tmonahan=removed\_email\_address@domain.invalid  
[[mailto:discuss-gnuradio-bounces+tmonahan=removed\_email\_address@domain.invalid](mailto:discuss-gnuradio-bounces+tmonahan=removed_email_address@domain.invalid)] On  
Behalf Of Nemanja S.  
Sent: Thursday, June 27, 2013 1:09 PM  
To: Stephen Harrison; GNURadio D.ion List  
Subject: Re: [Discuss-gnuradio] Operation of short to char

I think that I posted something similar few weeks ago. I also didn’t  
expect that 0-255 short goes to 0 char, and spent like a day trying to  
figure out the bug, but at the end it is like that.

On Thu, Jun 27, 2013 at 8:34 PM, Stephen Harrison  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:  
Hi,

Just wondering if the operation of short to char is a bug or  
intentional. The most significant 8 bits of the short gets converted to  
char, ie:

0-255 (short) → 0 (char)  
256-511 (short) → 1 (char)  
512-767 (short) → 2 (char)

This is not the operation I expected, but the unit test allows it to  
work this way, so I am confused.

Regards,

Stephen
