Created
November 4, 2016 06:09
Star
You must be signed in to star a gist
This file contains 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 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