Created
January 14, 2014 15:32
-
-
Save yvt/8420170 to your computer and use it in GitHub Desktop.
4n桁の2進数を逆順にして16進数にするCプログラム
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> | |
#define DIGIT(a) ((a)=='1'?1:0) | |
void rec(){ | |
int c = getchar(); | |
int c2 = getchar(), c3 = getchar(), c4 = getchar(); | |
if(c < 0) return; | |
rec(); | |
putchar("0123456789abcdef"[((DIGIT(c4)*2+DIGIT(c3))*2+DIGIT(c2))*2+DIGIT(c)]); | |
} | |
void main(){ | |
rec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment