#include <stdio.h>
int Count_one(int binary_number){
if(binary_number == 0) return 0;
return Count_one(binary_number / 10) + binary_number % 10;
}
long long int HexadecimaltoDecimal(long long int hexadecimal_number, int power){
if(hexadecimal_number == 0) return 0;
return HexadecimaltoDecimal(hexadecimal_number / 10, power * 16) + hexadecimal_number % 10 * power;
}
long long int DecimaltoBinary(long long int n, int power){
if(n == 0) return 0;
return DecimaltoBinary(n / 2, power * 10) + n % 2 * power;
}
int main(){
int time, num, b1, b2;
long long int X1, X2;
scanf("%d", &time);
for(int i = 0;i < time;i++){
scanf("%d",&num);
X1 = DecimaltoBinary(num, 1);
b1 = Count_one(X1);
printf("X1=%lld\n",X1); //為了看為什麼錯,而加上的
X2 = DecimaltoBinary(HexadecimaltoDecimal(num, 1), 1);
b2 = Count_one(X2);
printf("X2=%lld\n", X2); //為了看為什麼錯,而加上的
printf("%d %d\n", b1, b2);
}
return 0;
}
return DecimaltoBinary(n / 2, power * 10) + n % 2 * power;
這裡溢位了,power太大,int裝不下