Subj : Re: bit shifting To : comp.programming From : Rob Somers Date : Sun Aug 14 2005 03:52 pm > I don't think you've read Alex's post carefully enough. That is quite possible. > By the looks of > it, you wrote your code wrongly because you thought a "short" was 8 bits > when it is actually 16 bits. So your "~x" is not 127. I wrote my code to simulate the conditions needed to create the same results as the book I am using. Were I to leave out the cast to short, I would have generated 4294967167 from the ~128 operation. The book (which is just an old one I bought used) was apparently written at a time when an int might have been 2 bytes. My apologies for not getting all of this too quickly - I do feel like a bit of a dope. Anyway, I *think* I understand, so lets see if what I think is happening, is really happening. On paper, if I write down the number 128(decimal) in binary, it would look like this: 10000000 On paper, if I write down the number 127(decimal) in binary, it would look like this: 1111111 On paper, if I take 10000000 and do a complement operation on it, I get this: 01111111 But, on my computer,I am thinking 128 binary might look something more like this: 000...010000000, so that when I perform a complement operation on it, all the bits *before* the 1 and *after* get flipped, like so: 111...101111111. Does that make sense, and I am correct? .