Arithmatic in c

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kiran kher

    #1

    Arithmatic in c

    Hi All,

    I want to do arithmetic in c like below:

    A Op B = C
    1. 0x1100 Op 0x1000 = 0x0100
    2. 0x2300 Op 0x1000 = 0x0300
    3. 0x1000 Op ox1000 = 0x1000

    I know if I do A%B then I can get C. But it is true only for case 1 and 2. But in case 3 A%B will give 0x0000.

    I want to perform same operation on A and B to get C in all cases.

    If it is not possible by single operator i don't mind doing multiple operations on A and B to get C.

    Please help me in this.

    Hope my question make sense.

    Regards,
    Kiran
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    0x1000 % 0x1000 = 0x1000

    This is correct since the remainder of 0x1000/0x1000 is
    0x0000.

    All of your cases work using the % operator.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      @weaknessforcat s:
      x % x = 0 for (x != 0).

      @kiran:
      Where did this problem come from? Are you sure you copied case 3 accurately?

      Comment

      Working...