Skip to content

Instantly share code, notes, and snippets.

@duyet
Last active August 29, 2015 14:17
Show Gist options
  • Save duyet/3b34e2d3d351682b293c to your computer and use it in GitHub Desktop.
Save duyet/3b34e2d3d351682b293c to your computer and use it in GitHub Desktop.
// Van-Duyet Le <[email protected]>
// Home: http://lvduit.com
#include <stdio.h>
long dec2bin(int n) {
long result = 0;
for (int c = 31; c >= 0; c--) {
int k = n >> c;
if (k & 1)
result = result * 10 + 1;
else
result *= 10;
}
return result;
}
// Test it
int main() {
printf("%ld\n", dec2bin(3));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment