Skip to content

Instantly share code, notes, and snippets.

Created November 4, 2016 06:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anonymous/0094d9b04737c7c4b433230485f2a775 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define MAX 1000
char N[MAX];
void __init() {
for (int i = 0; i < MAX; i++) {
N[i] = 0;
}
}
int _strlen(char *str) {
for (int i = 0; i < MAX; i++) {
if (str[i] == '\0')
return i;
}
return -1;
}
int bin2dec(char *str) {
int ans = 0;
int pos = 0;
for (int i = _strlen(str) - 1; i >= 0; i--) {
if (str[i] == '1') {
ans += 1 << pos;
}
pos++;
}
return ans;
}
int main(void) {
__init();
scanf("%s", N);
int a = 17 * bin2dec(N);
int bin[MAX], o[MAX];
int res = 0;
int cnt = 0;
for (int i = 0; i < MAX; i++) {
res = a % 2;
a /= 2;
bin[i] = res;
if (a == 0) {
cnt = i + 1;
break;
}
}
for (int i = 0; i < cnt; i++) {
o[cnt - 1 - i] = bin[i];
}
for (int i = 0; i < cnt; i++) {
printf("%d", o[i]);
} printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment