Why do binary arithmetic operations sometimes result in different outputs?

  • Thread starter Thread starter megaflop
  • Start date Start date
  • Tags Tags
    Binary Error
AI Thread Summary
Binary arithmetic operations can yield different results due to the properties of integer division, particularly when odd integers are involved. When computing A + B versus 2 × (A/2 + B/2), the second operation can lead to discrepancies because of how binary addition handles carry bits, especially with odd numbers. The discussion highlights that integer division truncates towards zero, which can affect the outcome when odd integers are divided. This behavior is consistent across binary-coded integers. Understanding these nuances is crucial for accurate binary arithmetic computations.
megaflop
Messages
10
Reaction score
0
Hello everyone !
I got a problem, I can't figure out why when I compute A+B and 2\times (\frac{A}{2}+\frac{B}{2}) 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
Are you using integer or floating point ?

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

Got Basic?

FOR I = 1 , 10 , 1
PRINT I, INT( I/2)
NEXT I
END
 
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 :) .
 
megaflop said:
Integers I forgot to mention sorry.
Does only "misbehave" if you're using one or more odd integers? :rolleyes:
 
Hi all I have some confusion about piezoelectrical sensors combination. If i have three acoustic piezoelectrical sensors (with same receive sensitivity in dB ref V/1uPa) placed at specific distance, these sensors receive acoustic signal from a sound source placed at far field distance (Plane Wave) and from broadside. I receive output of these sensors through individual preamplifiers, add them through hardware like summer circuit adder or in software after digitization and in this way got an...
I have recently moved into a new (rather ancient) house and had a few trips of my Residual Current breaker. I dug out my old Socket tester which tell me the three pins are correct. But then the Red warning light tells me my socket(s) fail the loop test. I never had this before but my last house had an overhead supply with no Earth from the company. The tester said "get this checked" and the man said the (high but not ridiculous) earth resistance was acceptable. I stuck a new copper earth...
I am not an electrical engineering student, but a lowly apprentice electrician. I learn both on the job and also take classes for my apprenticeship. I recently wired my first transformer and I understand that the neutral and ground are bonded together in the transformer or in the service. What I don't understand is, if the neutral is a current carrying conductor, which is then bonded to the ground conductor, why does current only flow back to its source and not on the ground path...
Back
Top