Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: Convert uint16 to int16

Hybrid View

  1. #1
    Senior Member
    Join Date
    Jan 2015
    Location
    France
    Posts
    131

    Convert uint16 to int16

    Hello,

    Is there a simple and effective way to convert a uint16 value to a int16 value ?

    Turrently I use this :

    Code:
    tMot.mini = EEPROM.readInt(25);
    if (tMot.mini > 65000) tMot.mini = tMot.mini - 65536;
    readInt send an uint16_t value, so if the real value is -10, I get 65531.

    I tried :
    Code:
    tMot.mini = (int)EEPROM.readInt(25);
    But it don't work.
    Thank you,
    Manu

  2. #2
    Senior Member
    Join Date
    Jan 2015
    Location
    France
    Posts
    131
    To answer to myself :

    Code:
    tMot.mini = (int16_t)EEPROM.readInt(25);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •