bit-wise shift operator problem
Started by ●October 4, 2005
56805 DSP and I am trying to shift 16 places to the left into an unsigned
long (32-bit size).
unsigned long big_value = 0;
big_value = 1 << 16;
big_value is still zero.
What am I missing?
Reply by ●October 5, 20052005-10-05
Hello Mark
you probably have to type-cast the "1" into a long before the shift
operationg, otherwise the compiler treats it as a short integer,
shifting its 1 bit into nothingness.
big_value = (long)(1) << 16;
Best regards
Robert
On 04.10.2005, at 19:10, mark@mark... wrote:
>
> 56805 DSP and I am trying to shift 16 places to the left into an
> unsigned
> long (32-bit size).
>
> unsigned long big_value = 0;
>
> big_value = 1 << 16;
>
> big_value is still zero.
>
> What am I missing? >
you probably have to type-cast the "1" into a long before the shift
operationg, otherwise the compiler treats it as a short integer,
shifting its 1 bit into nothingness.
big_value = (long)(1) << 16;
Best regards
Robert
On 04.10.2005, at 19:10, mark@mark... wrote:
>
> 56805 DSP and I am trying to shift 16 places to the left into an
> unsigned
> long (32-bit size).
>
> unsigned long big_value = 0;
>
> big_value = 1 << 16;
>
> big_value is still zero.
>
> What am I missing? >
Reply by ●October 5, 20052005-10-05