[OCLUG-devel] question about bitwise ~

James Colannino james at colannino.org
Sun Jun 6 08:13:37 PDT 2004


Christopher Smith wrote:
> 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.

Oh, ok.  That makes sense.  I finished the chapter today and the book 
didn't mention anything about that, so I'm glad you answered my question 
   Otherwise I wouldn'tve known.  Playing with individual bits is 
actually a lot of fun.  It's a bit complicated for me, but as I re-read 
certain parts and practice it starts to get easier.  There's just 
something about being able to manipulate data at the sub-byte level (if 
that's an acceptable term  which I really find interesting.  It really 
helps me to understand how things work.

BTW, the first time I sent this message (yesterday), it didn't go 
through.  My mail was held in my ISP's queue for over 4 hrs. and then 
was spit back to me because the oclug mail server timed out.

James

-- 
My blog: http://www.crazydrclaw.com/
My homepage: http://james.colannino.org/

"There are no uninteresting things; only uninterested people." --G.K. 
Chesterton



More information about the OCLUG-devel mailing list