Optimization
Optimization with QB Logic
Use of NOT

```
a% = -a% - 1
```
is equivalent to
```
a% = NOT a%
```

Because the first piece of code has more operations in it, the second piece of code must be faster, and this is borne out in tests: the second is 1.44 times faster than the first.

NOT performs the 1's complement on the number, which means that it inverts all the bits of a number such as 00101110 to 11010001.

```
X    NOT
-----------
F    T
T    F
```
Note:
The signed binary system does not use a single negative sign to signify negativity, because then there would be +0 and -0. The Great Wise Ones decided that they wouldn't have that, and made the signed integer range between -n/2^2 - 1 to n/2^2 + 1. (8 bit values would go from -128 to 127)

Therefore, then, NOT is the same as a% = -a% - 1 because the number first has to be shifted by 1 up and then set to negative.

-Agamemnus

LogicChapterB - page last edited 2003-10-12 13:47:45 by 172.141.115.162 (home) (edit)
Blast WIKI - by RoboticBoy - edited and tweaked for our evil purposes by Hexadecimal Disaster