for(ch='A';dwDrives!=0;ch++,dwDrives = (dwDrives>>1))
what does 'dwDrives = (dwDrives>>1)' means ?
It is similar to "cin>>" in C++.......
Thanks you help
for(ch='A';dwDrives!=0;ch++,dwDrives = (dwDrives>>1))
what does 'dwDrives = (dwDrives>>1)' means ?
It is similar to "cin>>" in C++.......
Thanks you help
- dwDrives = (dwDrives>>1))
This is a bit shift. So if dwDrives has a binary value of this before:
10101010
after it would be:
01010101
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
In C, >> is the Bit Wise Right Shift Operator. When you say: dwDrives>>1, all the bits in the variable dwDrives are shifted once. Similarly, dwDrives>>4 means, the bits are right shifted 4 times.
Ex: if dwDrives = 23 (0001 0111) when (dwDrives >> 1), dwDrives would become: 11 (0000 1011)
And when (dwDrives >> 4), would become: 1 (0000 0001)
Similarly, << is the Left Shift Operator.
>> , << are the shift operators in C++ too, but are overloaded in case of cin and coutOriginally posted by shaik786
In C, >> is the Bit Wise Right Shift Operator. When you say: dwDrives>>1, all the bits in the variable dwDrives are shifted once. Similarly, dwDrives>>4 means, the bits are right shifted 4 times.
Ex: if dwDrives = 23 (0001 0111) when (dwDrives >> 1), dwDrives would become: 11 (0000 1011)
And when (dwDrives >> 4), would become: 1 (0000 0001)
Similarly, << is the Left Shift Operator.
Their overloading isn't restricted to cin/cout, other classes can overload this operator too. Just thought I'd highlight this factOriginally posted by pinko_liberal
>> , << are the shift operators in C++ too, but are overloaded in case of cin and cout
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
why the result is 11(0000 1011) after shift ?Originally posted by shaik786
Ex: if dwDrives = 23 (0001 0111) when (dwDrives >> 1), dwDrives would become: 11 (0000 1011)
[/B]
why isn't 1110 1000 ?
is these opeator (<<, >>) use very often ?
If you're doing a right shift (>>), you look at the binary representation, and move each bit right. The empty slot on the left will be filled with a zero.Originally posted by Kelvin
why the result is 11(0000 1011) after shift ?
why isn't 1110 1000 ?
is these opeator (<<, >>) use very often ?
So, 0001 0111 shift right one will be 0000 1011.
A simpler example:
Start with this:
>10000000
and shift right one becomes
>01000000
and so on.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
oh~thanks!!
I understand now
really thanks