My code works if I use operand 1 and operand 2 as integers. Using unsigned char operand 1 does not work. Can you help me?
int ALU(unsigned char operand1, unsigned char operand2)
{
printf("Enter Operand 1(in decimal): ");
scanf("%d",&operand1);
printf("\nEnter Operand 2(in decimal): ");
scanf("%d",&operand2);
char bin16_1[] = "0000000000000000";
int pos;
for (pos = 16; pos >= 0; --pos)
{
if (operand1 % 2)
bin16_1[pos] = '1';
operand1 /= 2;
}
printf("\n\nBinary Equivalence of Operand 1: %s",bin16_1);
If I input 4096 or 512 or 65536 as decimal, the output will be 0000 0000 0000 00000 which is wrong.