Why do binary arithmetic operations sometimes result in different outputs?

In summary, the conversation is discussing a problem with computing A+B and 2*(A/2 + B/2) where the results are sometimes different. The conversation also mentions the use of binary coding and integer or floating point calculations. Finally, the conversation concludes with a question about the possibility of the issue only occurring with odd integers.
  • #1
megaflop
10
0
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.
 
Engineering news on Phys.org
  • #2
Are you using integer or floating point ?

My guess is former , and one of the numerators is an odd number.
 
  • #3
Integers I forgot to mention sorry.
 
  • #4
Well there you go.

Got Basic?

FOR I = 1 , 10 , 1
PRINT I, INT( I/2)
NEXT I
END
 
  • #5
jim hardy said:
Well there you go.

Got Basic?

FOR I = 1 , 10 , 1
PRINT I, INT( I/2)
NEXT I
END

I see thank you :) .
 
  • #6
megaflop said:
Integers I forgot to mention sorry.
Does only "misbehave" if you're using one or more odd integers? :rolleyes:
 

What is an error in binary arithmetic?

An error in binary arithmetic refers to a mistake or deviation from the expected result in calculations involving binary numbers. This can occur due to limitations in the representation of numbers in binary form or due to human error in performing the calculations.

What are some common causes of errors in binary arithmetic?

Common causes of errors in binary arithmetic include rounding errors, overflow or underflow of numbers, and truncation of digits.

How can errors in binary arithmetic be minimized?

Errors in binary arithmetic can be minimized by using appropriate data types with sufficient precision to represent the numbers accurately, as well as by double-checking calculations for accuracy.

What is the impact of errors in binary arithmetic?

The impact of errors in binary arithmetic can range from minor discrepancies in calculations to significant errors that can affect the outcome of a program or experiment. In some cases, these errors can cause system crashes or incorrect data analysis.

Are there ways to detect and correct errors in binary arithmetic?

Yes, there are techniques such as error detection codes and error correction codes that can be applied to detect and correct errors in binary arithmetic. These involve adding extra bits to the binary representation to check for and correct any errors that may have occurred during calculations.

Similar threads

  • Programming and Computer Science
Replies
29
Views
2K
  • Linear and Abstract Algebra
Replies
13
Views
1K
  • Electrical Engineering
Replies
15
Views
2K
Replies
5
Views
2K
Replies
2
Views
6K
  • Advanced Physics Homework Help
Replies
2
Views
1K
Replies
10
Views
3K
  • Precalculus Mathematics Homework Help
Replies
6
Views
575
  • Computing and Technology
Replies
6
Views
1K
Back
Top