Hi,

I've been working on a project that needs to list all the drives on a computer (it's kind of a file explorer, but without using the standard one provided by windows). I've searched and found the function GetLogicalDrives(), which does exactly what I want.

However, the return value is a DWORD of which bit-position 0 represents the existince of drive A:/, bit-position 1 of B:/ and so on. I've found a few forum posts about bit-shifting, with which I have no experience.

This is what I got so far:

int main() {

  int bits[32]; // Array to put in the seperate bits of the DWORD
  DWORD input = 9; // This should give 10010000000000000000000000000000
  int i = 0; // Counter

  /* Looping through every bit of the DWORD: */
  for (i = 0; i < 32; i++) {
     bits[i] = input >> i;
     printf("bits[%d] = %d\n", i, bits[i]);
  }

}

But it isn't give the correct output. Does anyone know how to solve my problem :)?

Does anyone know how to do this?

Thanks in advance,
~G

I would write a few test programs that manipulate bits so you can understand what bit-shifting, ANDing, and ORing is all about. Then when you understand these basic principals, go back to your program with your new understanding.

Actually, the integer 9 would be (in 32-bit binary) 00000000000000000000000000001001

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.