Created
April 27, 2012 10:30
-
-
Save nissuk/2508233 to your computer and use it in GitHub Desktop.
C: 整数を2進数に変換して表示!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void main() { | |
int input; | |
int bit; | |
int show; | |
int i; | |
while (1) { | |
printf(">> "); | |
scanf("%d", &input); | |
show = 0; | |
for (i = sizeof(int) * 8 - 1; i > -1; i--) { | |
bit = (input & (1 << i)) >> i; | |
if (!show && bit == 1) show = 1; | |
if (show) printf("%d", bit); | |
} | |
puts(""); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment