Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Error in binary arithmetics

  1. Dec 17, 2012 #1
    Hello everyone !
    I got a problem, I can't figure out why when I compute [itex]A+B[/itex] and [itex]2\times (\frac{A}{2}+\frac{B}{2})[/itex] the result is sometimes different.
    Can anyone explain why the results of the two operations are different ?

    Edit : A and B are coded in binary of course and we compute a binary addition.
     
  2. jcsd
  3. Dec 17, 2012 #2

    jim hardy

    User Avatar
    Science Advisor
    Gold Member
    2016 Award

    Are you using integer or floating point ?

    My guess is former , and one of the numerators is an odd number.
     
  4. Dec 17, 2012 #3
    Integers I forgot to mention sorry.
     
  5. Dec 17, 2012 #4

    jim hardy

    User Avatar
    Science Advisor
    Gold Member
    2016 Award

    Well there ya go.

    Got Basic?

    FOR I = 1 , 10 , 1
    PRINT I, INT( I/2)
    NEXT I
    END
     
  6. Dec 17, 2012 #5
    I see thank you :) .
     
  7. Dec 17, 2012 #6

    uart

    User Avatar
    Science Advisor

    Does only "misbehave" if you're using one or more odd integers? :rolleyes:
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Error in binary arithmetics
  1. Binary divider circuit (Replies: 2)

  2. Binary counter help (Replies: 1)

  3. Binary number. (Replies: 5)

Loading...