typo in Fig 2.6? (x+1 vs x-1)

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

typo in Fig 2.6? (x+1 vs x-1)

kowey
The table in the Kindle edition seems to say that you compute x+1 with !(!x + 1) [nx, zy, ny, f=+, no], and conversely that you get x - 1 by taking x + 1 [zy, ny, f=+].  

Has that just been switched around or am I confused?  (Similarly for figure 4.3)
Reply | Threaded
Open this post in threaded view
|

Re: typo in Fig 2.6? (x+1 vs x-1)

kowey
Not a typo! Apologies. I was indeed confused and forgot that flipping 0 gets you a bunch of 1s
Reply | Threaded
Open this post in threaded view
|

Re: typo in Fig 2.6? (x+1 vs x-1)

Chas. Owens
In reply to this post by kowey
The result of zy and ny is that y is zeroed and then bitwise negated, so it will be 1111 1111 1111 1111 (or -1 in decimal).  You seem to be under the impression that it will be 1 (boolean not).  Let's examine x = 4, zx = 0, nx = 1, zy = 1, ny = 1, f = 1, no = 1

x = 0000 0000 0000 0100 : 4
~x = 1111 1111 1111 1011 : -5
~0 = 1111 1111 1111 1111 : -1
~x + ~0 = 1111 1111 1111 1010 : -6
~(~x + ~0) = 0000 0000 0000 0101 : 5

and now x = 4, zx = 0, nx = 0, zy = 1, ny = 1, f = 1, no = 0

x = 0000 0000 0000 0100 : 4
~0 = 1111 1111 1111 1111 : -1
x + ~0 = 0000 0000 0000 0011 : 3
Reply | Threaded
Open this post in threaded view
|

Re: typo in Fig 2.6? (x+1 vs x-1)

kowey
Many thanks! Yes, I indeed managed to confuse myself by thinking that flipping 0 got you 1, probably because I was thinking of the 0 as a single bit and not the full n bits.  

As an aside, it's really interesting for me from the standpoint of how my (broken) brain works, because I was really was thinking in terms of bit-flipping (ie. trying to puzzle through the algebra on paper, I was writing things like f(x) = 2^n - x - 1).  Hard to get what I'm trying to express.  It's not a case of consistently thinking a wrong thing such that correcting that wrong view fixes the problem.  It's more like a sort “flaky wiring” where you can think the right thing in one half of a sentence and then somehow switch to thinking the exact opposite in the other half!
Reply | Threaded
Open this post in threaded view
|

Re: typo in Fig 2.6? (x+1 vs x-1)

Lozminda
I too missed the bit wise negation, thinking Not 0 is 00..01. To be fair to the course it does say:

"The zy and ny bits are
1, so the y input is first zeroed, and then negated bit-wise. Bit-wise negation of zero, (000 ...00) two , gives
(111 ...11) two , the 2’s complement code of -1."

Phew, I was thinking fig 2.6 was completely wrong, as it turned out I was.  But at least we're making the same mistakes.

Great course btw, thanks all involved with Nand2Tetris.

I'm sure i'll be making other mistakes too.

All the best
Reply | Threaded
Open this post in threaded view
|

Re: typo in Fig 2.6? (x+1 vs x-1)

WBahn
Administrator
Lozminda wrote
Great course btw, thanks all involved with Nand2Tetris.

I'm sure i'll be making other mistakes too.
If you don't, then you will be missing out on the best learning opportunities!