Tuesday, June 23, 2015

BITWISE NOT OPERATOR


The bitwise NOT, or complement, is a unary operation that performs logical negation on each bit, forming the ones' complement of the given binary value. Bits that are 0 become 1, and those that are 1 become 0. For example:
NOT   0111(decimal 7)
  =      1000(decimal 8)

FOR SIGNED INTEGERS:
The bitwise complement is equal to the two's complement of the value minus one. If two's complement arithmetic is used, then
NOT x = −x − 1.


FOR UNSIGNED INTEGERS:
For unsigned integers, the bitwise complement of a number is the "mirror reflection" of the number across the half-way point of the unsigned integer's range. For example, for 8-bit unsigned integers, NOT x = 255 - x, which can be visualized on a graph as a downward line that effectively "flips" an increasing range from 0 to 255, to a decreasing range from 255 to 0. A simple but illustrative example use is to invert a grayscale image where each pixel is stored as an unsigned integer.

1 comment: