Arduino Forum

Products => Arduino Due => Topic started by: sohini25 on Jul 29, 2013, 12:42 am

Title: which data type can maintain 16 bits in Due?
Post by: sohini25 on Jul 29, 2013, 12:42 am
I need to maintain a 16 bit number in a variable and do some shift operations in it. Short is supposed to be 16 bits. But when I left shift my 16 bit number contained in a short variable it is giving an output of more than 16 bit.

Please tell me how can I restrict my output to 16 bits even after shifting.
Title: Re: which data type can maintain 16 bits in Due?
Post by: wmvdw on Jul 29, 2013, 11:56 am
Short should be 16bit(http://arduino.cc/en/Reference/short). What code are you using for the bitshifting?
Title: Re: which data type can maintain 16 bits in Due?
Post by: Grumpy_Mike on Jul 29, 2013, 12:06 pm
After the shift operation simply AND the result with a value of 0xffff
Code: [Select]

value = value << shift;
value = value & 0xffff;
Title: Re: which data type can maintain 16 bits in Due?
Post by: drm0hr on Jul 29, 2013, 03:56 pm
You can restrict the variable to 16 bits by using the int16_t or uint16_t (unsigned integer) types.