Author Topic: 2D Array in Arduino  (Read 3713 times)

0 Members and 1 Guest are viewing this topic.

Offline tiofilo75Topic starter

  • Contributor
  • Posts: 37
2D Array in Arduino
« on: September 11, 2013, 05:20:47 pm »
I am trying to print a 2D array but for some reason when I print an element higher than 0x7F the serial print appears to overflow. Here is an example:

 I define my array as :
unsigned int BANK[4][2]={{0x00,0x70},{0x01,0x85},{0x01,0x85},{0x00,0xe0}};

if I do a serial print of the second element of each array I will get the following:

70
FFFFFF85
FFFFFF85
FFFFFFE0

I don't know what is going on, why do I get the FFFFFF?  Can anyone please shed some light. Thanks.


 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: 2D Array in Arduino
« Reply #1 on: September 11, 2013, 06:18:49 pm »
they are being promoted to signed long.
================================
https://dannyelectronics.wordpress.com/
 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: 2D Array in Arduino
« Reply #2 on: September 11, 2013, 06:20:32 pm »
It looks like somewhere the numbers are being interpreted as signed 8-bit numbers, which are then being extended to 32-bit numbers.


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf