Why? Help,THANKS!

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Why? Help,THANKS!

Jump to solution
485 Views
lihao
Contributor I

# define  BUS   (48000000)

# define  PRE  (64)

# define  CLK    ( BUS / (10000*PRE) )

 

main()

{

     unsigned int  A;

     A= CLK;

}

 

******************************************

result:   A=CLK= 62411,    why? Help,Thank you!

Labels (1)
1 Solution
403 Views
kef
Specialist I

(int)10000 * (int)64 = (int)0xC400 = (int)-15360

(long)48000000 / (int)-15360 = -3125

(unsigned int)-3125 = 0xF3CB = 62411

Some UL's or typecasts are missing, try this:

# define  BUS   (48000000ul)

# define  CLK    ( BUS / (10000ul*PRE) )

View solution in original post

2 Replies
404 Views
kef
Specialist I

(int)10000 * (int)64 = (int)0xC400 = (int)-15360

(long)48000000 / (int)-15360 = -3125

(unsigned int)-3125 = 0xF3CB = 62411

Some UL's or typecasts are missing, try this:

# define  BUS   (48000000ul)

# define  CLK    ( BUS / (10000ul*PRE) )

403 Views
lihao
Contributor I

Thanks you very much!   Best wishes for you!

0 Kudos