Results 1 to 2 of 2
  1. #1
    25+ Posting Member
    Join Date
    Dec 2010
    Location
    Canada
    Posts
    26
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Tip: Use unsigned int for large values

    Just thought I'd share something that puzzled me for awhile. I can't find reference to this in the demos and don't see a post on it- if this has been shared before or is well known just delete this

    I use Link2fs to pull altitude and V/S for my pressure panel and during my final tests to full cruise my display of ALT went crazy. After scratching my head a while I found out that using the example code (assigning the retrieved values as int) wont work for altitude on my board (or Uno apparently). An int maxes out at 32,767 on the positive side. Nearly the same on the negative.

    I found switching over to "unsigned int" allows up to 65,535 and only uses the positive side (perfect for altitude in my Lear)

    Code:
     case 'D':    {
         alt = "";  // Get altitude
         alt += getChar();
         alt += getChar();
         alt += getChar();
         alt += getChar();
         alt += getChar();
      unsigned int alt1 = alt.toInt(); //
    If this is already well known just delete my post. It sure made me scratch my head for a bit when everything worked perfect untill I hit FL320

    If you are flying an SR71 of something- I guess you'd need a different way again.

    Cheers
    Eric

  2. Thanks Charan thanked for this post
    Likes Charan, JMeller liked this post
  3. #2
    25+ Posting Member
    Join Date
    Dec 2010
    Location
    Canada
    Posts
    26
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Tip: Use unsigned int for large values

    As usual watching some videos and learning- looks like if you fly an SR71 or the space shuttle- and "unsigned long" should work like a champ

    If I understand it right- for an integer using "unsigned" limits it to just the positive side. Long adds a tonne more storage (at the expense of memory). Just sharing for any other people learning like me

    Cheers