This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Arithametics

Hi All,

I am experiencing a basic problem in the arithametic of the instrucation

A = ((B-C)*100)/204

during execution of the instruction, if the result of (B-C)*100 is greater than 16 bits what will happen? for avoiding data loss do I have to declare it as 32 bit variable or the proceesor will handle it without changing the size?

Variable A is declared as 16 bit.

do I have to use both B and C 32 bit if i conditionally change the instrucation as

A = ((C-B)*100)/204

during execution ?

my code will look like this


if (B>C) A = ((B-C)*100)/204;

else if (C>B) A = ((C-B)*100)/204 ;


my processor is C8051F020
compiler is C51

best regards
Deepak

Parents
  • Hi,

    Please bear with me .. I know this is not where I have to discuss about standard 'C'. But sorry for that because here no body is near me to help me out with C coding and am very new to 'C' just like a kid learning to Walk !! I used to do it in assembly only.

    I tried Hans-Bernhard Broeker's advice and it worked. Thanks Mr. Hans-Bernhard Broeker.
    Thank you all for taking ur valuable time for me.
    If you don't mind give one more help. I have defined 100 in that code with a name HUNDRED to avoide usage of 'magic number' in the code. but .. how should i use Mr. Hans-Bernhard Broeker's advice with the define???

    Really sorry for bothering you all

    thanks
    Deepak

Reply
  • Hi,

    Please bear with me .. I know this is not where I have to discuss about standard 'C'. But sorry for that because here no body is near me to help me out with C coding and am very new to 'C' just like a kid learning to Walk !! I used to do it in assembly only.

    I tried Hans-Bernhard Broeker's advice and it worked. Thanks Mr. Hans-Bernhard Broeker.
    Thank you all for taking ur valuable time for me.
    If you don't mind give one more help. I have defined 100 in that code with a name HUNDRED to avoide usage of 'magic number' in the code. but .. how should i use Mr. Hans-Bernhard Broeker's advice with the define???

    Really sorry for bothering you all

    thanks
    Deepak

Children