(e-mail address removed) said:
Oh boy... I'm tempted to suggest you a carreer change or plainly tell
you how big of an id**t you are.
It seemed like a reasonable question to me, albeit one that is answered in
the FAQ and in K&R, which it would have been wise of the OP to check first.
Really! Want to know why? One word: research!
Okay, let's see where your "research" takes us...
Did you ever tried searching with google about bitwise operations in C?
Google is not selective. You could write a page like this:
+----------------------------------------------------------+
|
http://www.lousytips.disinformation.org/bitunwise.html |
+----------------------------------------------------------+
| |
| Bitwise operations in C |
| ----------------------- |
| |
| C doesn't support bitwise operations. Use BASIC instead. |
| |
+----------------------------------------------------------+
....and Google would cheerfully index it without prejudice.
I spent 1 minute just to prove I was right and I found
a couple of sites explaining it very well. This one for example:
http://www.cprogramming.com/tutorial/bitwise_operators.html
That site has a very poor reputation with regard to C programming. But never
mind that - let's look at the page itself:
"Generally, as a programmer you don't need to concern yourself about
operations at the bit level." Well, that's as maybe, but if he didn't need
to know the answer he wouldn't have asked the question. Personally, I find
myself doing bit manipulations fairly regularly. Not only do they have
useful applications in cryptography and graphics, but they are also
essential for n-bit numbers (the more so when n > sizeof(largest integer
type) * CHAR_BIT), and useful for such things as Bloom filters.
After three and a half lines of generalised text, we find (or at least, I
found) advertisements for Prismtech, Microsoft, and "National", whatever
that is. A naive reader might well stop right there, thinking the article
was over. Interspersing ads in the text is thoughtless and exploitative.
"By convention, in C and C++ you can think about binary numbers..."
There is no such thing as a binary number. The author is confusing number
with number representation.
"10000000 is 128"
No, it isn't.
"the results of the left and right shift operators are not implementation
dependent for unsigned numbers"
Yes, they are, whether the author means "unsigned numbers" or "unsigned
types". The result of 1L << 32 is undefined on some systems, and
well-defined on others.
"Note that in this example, we're using integers, which are either 2 or 4
bytes..."
It is not clear whether the author means that integers are guaranteed to be
2 or 4 bytes (which they are not). If that is not what is meant, though, it
is hard to see why the author would have bothered to say anything, since
the example in question is simply: return number << power; which is not
dependent on any particular integer size, except in terms of the allowable
values of power, which the example does not check at all.
"128 * 2 = 256, and we can't even store a number that big in a byte..."
We can if CHAR_BIT >= 9.
The page has other such errors, and I cannot recommend it.
So much for "research". There is more to research than typing a few search
terms into Google.