2 ms·
The first source I found online said that ~ was defined as the one's-complement operator and therefore had the effect of flipping bits. It's defined that way o
by AnimalMuppet 7y ago
The first source I found online said that ~ was defined as the one's-complement operator and therefore had the effect of flipping bits. It's defined that way on all architectures, whether one's-complement, two's-complement, or something else.
If you think about it, all of the bitwise operators had better be defined just in terms of the bits. Bitwise and, for example, had better be defined as the AND of the bits. No exceptions for the sign bits (or for anything else).
- kragen 7y agoI read the Interdata 8/32 and Z8000 manuals and explained the historical developments that motivated the development of C compilers to you, and you come back with "the first source I found online said"? C'mon, gimme a specific source talking about how a specific one's-complement (or sign-magnitude) compiler handled "~", or go home.
- AnimalMuppet 7y agohttp://www.cplusplus.com/doc/tutorial/operators/ http://www.cplusplus.com/doc/tutorial/operators/ https://www.geeksforgeeks.org/bitwise-operators-in-c-cpp/ https://www.geeksforgeeks.org/bitwise-operators-in-c-cpp/ https://www.tutorialspoint.com/cprogramming/c_operators.htm https://www.tutorialspoint.com/cprogramming/c_operators.htm All say the same thing. (But, BTW, I am home.)
- kragen 7y agoOnly the first of those is a reliable source, and it doesn't mention one's complement machines at all, or for that matter C. It's a summary of the C++ standard, which agrees with the C standard on the relevant points, but both are considerably more liberal than the practical requirements on actual implementations of the languages. It seems that you have no experience of or reliable knowledge about programming in C on one's-complement or sign-magnitude machines, and furthermore you seem to be unclear on the difference between C and C++. So probably you shouldn't be so confident in your opinions!
- AnimalMuppet 7y agoThe first of those literally says "Unary complement (bit inversion)". That's what the standard says. "Bit inversion" tells you exactly what's supposed to happen, regardless of the architecture of the machine. Or is your claim that the website, despite being based on the C++ standard, is simplifying it by assuming that all machines are two's-complement? All right then, what is the actual text of the C++ standard? (You're the one making the claim that on ones-complement machines, the standard doesn't require what everyone thinks it does, so you get the burden of proof. Also, I don't have access to the text of the standard.) So far as I know, the C standard does not differ from the C++ standard on what that operator does. If you claim it does, I'll ask you to document it. Instead of throwing insults at others' level of knowledge, I suspect you should be a bit more cautious about your own.