I'm writing a program to multiply two 4-bit number using add and shift method in C language. The code is as follows:
#include <stdio.h>
#include <math.h>
int main()
{
int d,p=0, y=1010, x=1101, c, i;
for(i=0;i<=3;i++)
{
c = x % 10;
y = y << i;
d = c*y;
p = p ^ d;
x = x / 10;
}
printf("%d",p);
return 0;
}
I'm getting answer as 57570 which is wrong. Where am I going wrong?