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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×