in reply to Re: Boolean calculation incorrect values
in thread Boolean calculation incorrect values

The preferred term is bitwise complement. Most computer arithmetic uses two's complement to represent numbers so the complement and the negation of a bit pattern are not the same. Because the two's complement negation of a number is equivalent to the one's complement negation plus 1, the two's complement negation of a single bit number is the same as the original number!

Which all seems a whole lot more pedantic than I really intended, but the notion that negating a number leaves it unchanged was just too neat to pass up :-D.

Premature optimization is the root of all job security
  • Comment on Re^2: Boolean calculation incorrect values

Replies are listed 'Best First'.
Re^3: Boolean calculation incorrect values
by Athanasius (Archbishop) on Dec 24, 2015 at 08:58 UTC

    ++ for two useful and important points — 1’s vs. 2’s complement, and negation leaving a number unchanged (!) — but I have to disagree about the terminology. “Bitwise complement” is ambiguous for precisely the reasons you give, unless “1’s complement” is explicitly specified. But “bitwise negation” is unambiguous, and is the term used in the official documentation (perlop#Symbolic-Unary-Operators):

    Unary "~" performs bitwise negation, that is, 1's complement. For example, 0666 & ~027 is 0640. ... Note that the width of the result is platform-dependent: ~0 is 32 bits wide on a 32-bit platform, but 64 bits wide on a 64-bit platform, so if you are expecting a certain bit width, remember to use the "&" operator to mask off the excess bits.

    The Camel Book refers to ~ as “bitwise NOT” (4th Edition, p. 118).

    Happy Christmas,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,