How do computers compare numbers?

498 views

Example: How does a computer know that 8 ist greater than 3?
Because it works in binary, how does it know that 1000 (8) is greater than 0011 (3)?

In: 2

8 Answers

Anonymous 0 Comments

The computer doesn’t “know”. There is a mechanical procedure to do it. It’s the same one you learned in school.

If you want to test if A > B:

Scan the bits from left to right (most significant bit to least-significant)

– If the A bit is 1 and the B bit is 0 then stop. A > B

– If the A bit is 0 and the B bit is 1 then stop. B > A

– If the A bit is equal to the B bit, then go to the next bit

If all the bits were scanned, then A = B.

This is encoded in a circuit that has inputs for the two numbers.

You are viewing 1 out of 8 answers, click here to view all answers.