Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

x-y = x+¬y+1 problem

I am currently reading a book about "bit fiddling" and the following formula appears:

x-y = x+¬y+1

But this doesn't seem to work. Example:

x = 0100  
y = 0010  
x-y = 0010  
¬y = 1101  
¬y+1 = 1110  
x+1110 = 10010  

But 10010 != 0010...

Where did I make a mistake (if any)?

(The book is "Hacker's Delight" by Henry S. Warren.)

like image 555
0x90 Avatar asked Aug 10 '10 22:08

0x90


People also ask

What is the problem with X and Y?

The XY problem is a communication problem encountered in help desk, technical support, software engineering, or customer service situations where the question is about an end user's attempted solution (Y) rather than the root problem itself (X).

How do you solve problems with one variable equations?

Solving Linear Equations in One VariableStep 1: Using LCM, clear the fractions if any. Step 2: Simplify both sides of the equation. Step 3: Isolate the variable. Step 4: Verify your answer.


1 Answers

You only have a four bit system! That extra 1 on the left of your final result can't exist. It should be:

x  = 0100
y  = 0010
~y = 1101
~y + 1 = 1110
x + 1110 = 0010

The other bit overflows, and isn't part of your result. You may want to read up on two's complement arithmetic.

like image 69
Carl Norum Avatar answered Jan 21 '23 12:01

Carl Norum