Thread: Just a little question~~you can help

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    85

    Just a little question~~you can 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

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    - 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]

  3. #3
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    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.

  4. #4
    Registered User pinko_liberal's Avatar
    Join Date
    Oct 2001
    Posts
    284
    Originally 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.
    >> , << are the shift operators in C++ too, but are overloaded in case of cin and cout

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by pinko_liberal
    >> , << are the shift operators in C++ too, but are overloaded in case of cin and cout
    Their overloading isn't restricted to cin/cout, other classes can overload this operator too. Just thought I'd highlight this fact
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Registered User
    Join Date
    Jul 2002
    Posts
    85
    Originally posted by shaik786
    Ex: if dwDrives = 23 (0001 0111) when (dwDrives >> 1), dwDrives would become: 11 (0000 1011)
    [/B]
    why the result is 11(0000 1011) after shift ?
    why isn't 1110 1000 ?

    is these opeator (<<, >>) use very often ?

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by Kelvin


    why the result is 11(0000 1011) after shift ?
    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.

    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]

  8. #8
    Registered User
    Join Date
    Jul 2002
    Posts
    85
    oh~thanks!!
    I understand now
    really thanks

Popular pages Recent additions subscribe to a feed