[OCLUG-devel] question about bitwise ~

Christopher Smith x at xman.org
Sat Jun 5 10:43:34 PDT 2004


On Sat, 2004-06-05 at 10:33, James Colannino wrote:
> Hey everyone.  I just have a simple question.  I learned that the ~ 
> operator inverts all the bits in an operand.  So, for example, say that 
> a byte (a character) contains 10000110.  It would become 01111001.  I've 
> tried this on characters and integers.  Both work fine.  However, I 
> tried this on a float, and I got the following error from the compiler:
> 
> error: wrong type argument to bit-complement
> 
> Does anyone know why this won't work on a floating point variable?  It 
> seems to me that since all data types are constructed of bits, this 
> should work, although the book has been very basic so far, and I also 
> haven't finished the chapter, so I may be missing something.

bitwise operators only work on integer types (characters are actually
integer types in C). Floating point numbers can have different
representations on different architectures, and performing the ~ on them
would likely leave you with nothing of value. So, the language is
designed to catch what is likely an error.

--Chris


More information about the OCLUG-devel mailing list