Deitel & Deitel, C How to Program 6th Edition, Exercise 10.18 (Portable displayBits Function)
// 10.18 (Portable displayBits Function)
void displayBits(int num) {
int i, mask = 1, intSize;
intSize = sizeof(int) * 8;
mask <<= intSize - 1;
for (i = 1; i <= intSize; i++) {
printf("%d", mask & num ? 1 : 0);
i % 8 ? 0 : printf(" ");
num <<= 1;
}
printf("\n");
}
void displayBits(int num) {
int i, mask = 1, intSize;
intSize = sizeof(int) * 8;
mask <<= intSize - 1;
for (i = 1; i <= intSize; i++) {
printf("%d", mask & num ? 1 : 0);
i % 8 ? 0 : printf(" ");
num <<= 1;
}
printf("\n");
}
Let me know in the comments if this page helped you somehow.
It is nice to know if my work helped someone, thanks :)
Comments
Post a Comment