Cryptography Reference
In-Depth Information
The XOR Operation
Finally, the Exclusive OR ( XOR ) operation is just like OR, except that if both bits
are 1, the output is 0. For example,
10101101 (173)
^ 01101011 (107)
11000110 (198)
What makes XOR particularly interesting is that it's invertible; this important
property is examined in depth in Chapter 2.
Position Shifting of Binary Numbers
Binary numbers can also meaningfully be shifted . Shifting a binary number
consists of moving all of the bits in one direction. Just as adding a zero to a
decimal number multiplies it by 10, shifting the bits in a binary number to the
left doubles its value. Similarly, shifting to the right halves it.
Two's-Complement Representation of Negative
Numbers
Because humans are so bad at performing mathematical computations, com-
puters were invented to reliably add and subtract numbers. Although we've
found a few additional purposes for which we can use computers, they're still
fundamentally adding and subtracting machines. However, no computer can
add or subtract infi nitely. Every ALU has a register size that dictates how many
bits represent a number; if an arithmetic operation needs more bits than the
register size, the operation overfl ows, and wraps back around to a logically
smaller number.
The idea behind two's-complement arithmetic is to split the available space
in half, assigning one half positive numbers and the other negative numbers.
Because, logically, negative numbers are smaller than positive numbers, you
might guess that the fi rst ( lowest ) half are the negative numbers and that the
last half are the positive numbers. However, for compatibility with unsigned
numbers, the fi rst half are the positives, and the last half are the negatives.
Because the last ( greatest ) half of any binary number space is the half with
the most-significant-bit ( MSB ) set, this provides an easy check for a negative
number — if the MSB is set, the number is negative. This also simplifi es the pro-
cess of negating a number. If you just invert the bits — apply the NOT operation
on all of them — you get the proper representation of the same number, with the
sign reversed. This representation is called one's complement arithmetic. The only
trick here is that if you invert 0 — binary 00000000 — you get 11111111. Th is is - 0,
 
Search WWH ::




Custom Search