I am fairly new to programming. I am having trouble converting a decimal int to a binary int. The goal is to input two ASCII values (lets say they are AB) and convert that into a binary integer without using arrays to store the binary value. I have tried many things to try and fix the problem but the logic that I have in my program is very logical and makes sense to me. The output of the program is 1488373225 if you input an 'AB'. Thanks in advance!
Here is my code:
int converttoBinary(char input[MAX_1]){
int temp2 = 0, rem = 0, i = 1, binary = 0, temp = 0;
printf("\n");
temp = input[0];
temp2 = input[1] * 100;
temp = temp + temp2;
printf("%d", temp);
while (temp > 0){
rem = temp % 2;
binary += rem * i;
i *= 10;
temp /= 2;
}
printf("The final binary value of %s is: %d", input, binary);
return binary;
}