还请各位写下来吧
#include <stdio.h>
#include <limits.h>
#include <memory.h>
void uintToBin(unsigned int num, char *pArray)
{
unsigned int bit = ~(UINT_MAX >> 1);
while (!(num & bit))
bit >>= 1;
while (bit) {
*pArray++ = num & bit ? '1' : '0';
bit >>= 1;
}
}
void uintToBinAll(unsigned int num, char *pArray)
{
unsigned int bit = ~(UINT_MAX >> 1);
while (bit) {
*pArray++ = num & bit ? '1' : '0';
bit >>= 1;
}
}
#define BUFSIZE (sizeof(unsigned int)*8 + 1)
int main()
{
char buf[BUFSIZE];
memset(buf, 0, BUFSIZE);
uintToBin(475, buf);
printf("%s\n", buf);
memset(buf, 0, BUFSIZE);
uintToBinAll(475, buf);
printf("%s\n", buf);
return 0;
}
写了一个位操作的