Skip to content

Instantly share code, notes, and snippets.

@yvt
Created January 14, 2014 15:32
Show Gist options
  • Save yvt/8420170 to your computer and use it in GitHub Desktop.
Save yvt/8420170 to your computer and use it in GitHub Desktop.
4n桁の2進数を逆順にして16進数にするCプログラム
#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