Why We Use Two’s Complement

Previously we discussed the mathematical foundations of computer integers and found that, as far as arithmetic is concerned, we can choose to use any range of N = 2m numbers, and the arithmetic operations that have to be implemented in hardware are not affected. Why is it then that in most programming languages we are …

Converting decimal numbers to fractions

Given that computer numbers have a finite precision, a calculation like 20/3 produces a result like 6.66667, which is slightly off. This begs the question: can we reverse the division operation, to make a routine that outputs “20/3” when it’s given the approximate value? One trick is to take a large number as the denominator. …