Pages: [1]   Go Down
Author Topic: Arduino Due: 16-bit int and others data types  (Read 1347 times)
0 Members and 1 Guest are viewing this topic.
Antofagasta - Chile
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!

how can i get an 16 bit signed int in arduino Due?

i'm working with 16-bit i2c and 32 bit integers make my life very dificult.

word is 16-bit, but it is unsigned.

Please, help me.
Logged

Antofagasta - Chile
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i forgot!

It would be great to have a data type table for Arduino Due.
Logged

Offline Offline
Newbie
*
Karma: 2
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would encourage you to use stdint.h. This has types such as uint16_t, int16_t etc if you need to be explicit about bit widths.
Logged

Antofagasta - Chile
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you!
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 6
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

As a side note, use the sizeof() function if you're not sure how many bytes a data type is.
Logged

Offline Offline
Sr. Member
****
Karma: 0
Posts: 339
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#include <stdint.h>

void setup() {
  Serial.begin(96200);
}

void loop() {
  Serial.print("sizeof(byte)="); Serial.println(sizeof(byte));
  Serial.println();
  Serial.print("sizeof(char)="); Serial.println(sizeof(char));
  Serial.println();
  Serial.print("sizeof(short)="); Serial.println(sizeof(short));
  Serial.println();
  Serial.print("sizeof(int)="); Serial.println(sizeof(int));
  Serial.println();
  Serial.print("sizeof(long)="); Serial.println(sizeof(long));
  Serial.println();
  Serial.print("sizeof(long long)="); Serial.println(sizeof(long long));
  Serial.println();
  Serial.print("sizeof(bool)="); Serial.println(sizeof(bool));
  Serial.println();
  Serial.print("sizeof(boolean)="); Serial.println(sizeof(boolean));
  Serial.println();
  Serial.print("sizeof(float)="); Serial.println(sizeof(float));
  Serial.println();
  Serial.print("sizeof(double)="); Serial.println(sizeof(double));
  Serial.println();
  Serial.print("sizeof(int8_t)="); Serial.println(sizeof(int8_t));
  Serial.println();
  Serial.print("sizeof(int16_t)="); Serial.println(sizeof(int16_t));
  Serial.println();
  Serial.print("sizeof(int32_t)="); Serial.println(sizeof(int32_t));
  Serial.println();
  Serial.print("sizeof(int64_t)="); Serial.println(sizeof(int64_t));
  Serial.println();
  Serial.print("sizeof(uint8_t)="); Serial.println(sizeof(uint8_t));
  Serial.println();
  Serial.print("sizeof(uint16_t)="); Serial.println(sizeof(uint16_t));
  Serial.println();
  Serial.print("sizeof(uint32_t)="); Serial.println(sizeof(uint32_t));
  Serial.println();
  Serial.print("sizeof(uint64_t)="); Serial.println(sizeof(uint64_t));
  Serial.println();
  Serial.print("sizeof(char*)="); Serial.println(sizeof(char*));
  Serial.println();
  Serial.print("sizeof(int*)="); Serial.println(sizeof(int*));
  Serial.println();
  Serial.print("sizeof(long*)="); Serial.println(sizeof(long*));
  Serial.println();
  Serial.print("sizeof(float*)="); Serial.println(sizeof(float*));
  Serial.println();
  Serial.print("sizeof(double*)="); Serial.println(sizeof(double*));
  Serial.println();
  Serial.print("sizeof(void*)="); Serial.println(sizeof(void*));
  Serial.println();
  delay(10000);
}
Logged

10 LET Loop=Infinite
20 GO TO 10

Pages: [1]   Go Up
Jump to: