Jump to content
Sign in to follow this  
miria

Unexpected result with unsigned short int type

Recommended Posts

I wrote a simple code in C, but when I port it to mspgcc it doesn't give me the right value. This is my code:

 

#include 
#include "uart1.h"
#include 
#include 
#include 
#include 
int putchar(int c)
  {
  return uart1_putchar(c);
  }

int main(void) 
  {
  //variables
    unsigned short int xk=3588, yk=47541, yk1, sig=10, de=1;

    unsigned long xk1;
    uart1_init();
    xk1=( xk+(sig*((unsigned long)yk-xk)*de));

    yk1=xk1 % 65535;

    printf("xk1=%6lx\t\n,",xk1);

    printf("yk1=%u\t\n,",yk1);


    }

THe result that I want is xk1=443118 and yk1=49908, but in mspgcc it gives me xk1=fffbc2ee and yk1=49902

I'm working with msp430-gcc-4.4.3

any idea

thanks

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...