Skip to content

Instantly share code, notes, and snippets.

@shahril96
Last active April 6, 2016 13:23
Show Gist options
  • Save shahril96/5b2aa327b43e64a62ab427178e86736f to your computer and use it in GitHub Desktop.
Save shahril96/5b2aa327b43e64a62ab427178e86736f to your computer and use it in GitHub Desktop.
Convert base-10 integer to any base-N (base 2 until base 10) presentation
#include <stdio.h>
void int2bin(int n, int base) {
if(n > 0) {
int2bin(n / base, base);
printf("%d ", n % base);
}
}
int main() {
int2bin(999, 2);
puts("");
int2bin(3103, 10);
puts("");
int2bin(10000, 3);
puts("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment