Go Down

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


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.


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


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

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


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

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131