#include <stdio.h>
#include <stdint.h>
#include <malloc.h>
void print_base(uint16_t num, uint8_t base) {\
if(num==0) printf("0");
if(base == 16) {
char hex[] = "0123456789ABCDEF";
char* s = (char *)malloc(10 * sizeof(char));
int i=0;
while(num) {
s[i++] = hex[num % 16];
num = num/16;
}
i--;
while(i>=0){
printf("%c",s[i]);
i--;
}
}
else {
uint16_t temp = num;
int count =0;
while(temp){
count++;
temp = temp >> 1;
}
for(int i=count-1;i>=0;i--){
printf("%d",(num>>i)&1);
}
}
}
int main() {
uint16_t num;
uint8_t base;
scanf("%hu %hhu", &num, &base);
print_base(num, base);
return 0;
}
Input
10 2
Expected Output
1010