Pages: [1]   Go Down
Author Topic: which data type can maintain 16 bits in Due?  (Read 526 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Enschede, The Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33379
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

After the shift operation simply AND the result with a value of 0xffff
 
Code:
value = value << shift;
 value = value & 0xffff;
Logged

Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: