You are a stupid programmer, you can't have that
H. S. Teoh
hsteoh at quickfur.ath.cx
Mon Aug 9 21:05:05 UTC 2021
On Mon, Aug 09, 2021 at 08:18:26PM +0000, Paul Backus via Digitalmars-d wrote:
> On Monday, 9 August 2021 at 19:23:14 UTC, H. S. Teoh wrote:
> > As Knuth once said:
> >
> > People who are more than casually interested in computers should
> > have at least some idea of what the underlying hardware is like.
> > Otherwise the programs they write will be pretty weird.
> > -- D. Knuth
> >
> > That includes knowing the ugly realities of 2's complement
> > arithmetic.
>
> The way I remember it, 2's complement notation is a method of encoding
> signed integers as unsigned integers such that a CPU can use the same
> instructions and circuits for both signed and unsigned arithmetic.
>
> So, from the hardware's point of view, unsigned arithmetic is the
> pure, simple version, and signed arithmetic is the ugly, complex
> version. :)
Indeed! If you look at the assembly level, unsigned arithmetic is the
one with straightforward instructions mapping 1-to-1 with arithmetic
operations, whereas signed arithmetic is the one that involves carry
bits and other such additional complications.
T
--
Heads I win, tails you lose.
More information about the Digitalmars-d
mailing list