Go Down

Topic: which data type can maintain 16 bits in Due? (Read 623 times) previous topic - next topic

sohini25

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.

wmvdw

Short should be 16bit(http://arduino.cc/en/Reference/short). What code are you using for the bitshifting?

Grumpy_Mike

After the shift operation simply AND the result with a value of 0xffff
Code: [Select]

value = value << shift;
value = value & 0xffff;

drm0hr

You can restrict the variable to 16 bits by using the int16_t or uint16_t (unsigned integer) types.

Go Up