# Binary Multiplication CPP

Binary …. yani ikilik düzeyde çarpma yapan ve bunu size adım adım gösteren C programı.

Doğu Akdeniz Üniversitesi Bilgisayar Mühendisliği 1. Sınıf ödevlerinden birisiydi.

#include <stdio.h>

#include <dos.h>

#include <conio.h>

#include <iostream.h>

#define size2 8

void first(void);

void second(void);

void result(void);

void show(void);

void shift(void);

void dec2bin (int ,int []);

void unsign(void);

void mm2(void);

int t,re,i=0,iz=0;

int secim;

int buffer[size2];

int deger=0,diger=0;

long res=0;

int multiplicand,multiplier,m[size2],q[size2];

int carry;

int m2[size2];

void main()

{

do

{

clrscr();

printf(”

Please Enter Which Technic you will use … “);

printf(”
=====>  1 for Unsigned <=====    “);

printf(”
=====>  2 for Boot’s   <=====    “);

printf(”
=====>  “);

scanf(“%d”,&secim);

}while((secim<0)||(secim>2));

if(secim==1)

first();

else

second();

}

void first()

{

do

{

clrscr();

printf(“Enter a Integer numer : “);

scanf(“%d”,&multiplicand);

printf(”
Enter other Integer number : “);

scanf(“%d”,&multiplier);

}while((multiplicand<0)||(multiplier<0));

dec2bin (multiplicand,q);

dec2bin (multiplier,m);

unsign();

getch();

}

void dec2bin (int dec,int arr[])

{

int input = dec;

int count = 0;

do

{

i = input%2;

arr[count] = i;

input = input/2;

count++;

}while (input > 0);

for(i=count;i<size2;i++)

{

arr[i]=0;

}

count=size2;

printf (“Binary representation is: “);

do

{

printf (“%d”, arr[count – 1]);

count–;

} while (count > 0);

printf (”
“);

}

void unsign()

{

t=size2;

carry=0;

for(i=0;i<size2;i++)

buffer[i]=0;

show();

do

{

if(q[0]==0)

{

shift();

show();

t–;

iz++;

printf(” %d .part

“,iz);

}

else if(q[0]==1)

{

shift();

show();

t–;

iz++;

printf(” %d .part

“,iz);

}

}while(t>0);

result();

}

void result(void)

{

int counter=0;

diger=0;

for(i=0;i<size2;i++)

{

deger=q[i];

diger=diger*2;

if(counter==0)

diger=1;

printf(”
%d %d”,deger,diger);

res+=deger*diger;

++counter;

}

printf(”
“);

for(i=0;i<size2;i++)

{

deger=buffer[i];

diger=diger*2;

printf(”
%d %d”,deger,diger);

res+=deger*diger;

++counter;

}

printf(”

}

void show(void)

{

printf(”
%d “,carry);

for(i=size2-1;i>=0;i–)

printf(“%d”,buffer[i]);

printf(” “);

for(i=size2-1;i>=0;i–)

printf(“%d”,q[i]);

printf(” “);

for(i=size2-1;i>=0;i–)

printf(“%d”,m[i]);

printf(” “);

}

void shift(void)

{

for(i=0;i<size2-1;i++)

q[i]=q[i+1];

q[size2-1]=buffer[0];

for(i=0;i<size2-1;i++)

buffer[i]=buffer[i+1];

buffer[size2-1]=carry;

}

{

for(i=0;i<size2-1;i++)

{

if((buffer[i]==0)&&(m[i]==0)&&(carry==0))

{

buffer[i]=0;

carry=0;

}

else if((buffer[i]==0)&&(m[i]==0)&&(carry==1))

{

buffer[i]=1;

carry=0;

}

else if((buffer[i]==0)&&(m[i]==1)&&(carry==0))

{

buffer[i]=1;

carry=0;

}

else if((buffer[i]==1)&&(m[i]==0)&&(carry==0))

{

buffer[i]=1;

carry=0;

}

else if((buffer[i]==1)&&(m[i]==1)&&(carry==1))

{

buffer[i]=1;

carry=1;

}

else if((buffer[i]==1)&&(m[i]==1)&&(carry==0))

{

buffer[i]=0;

carry=1;

}

else if((buffer[i]==1)&&(m[i]==0)&&(carry==1))

{

buffer[i]=0;

carry=1;

}

else if((buffer[i]==0)&&(m[i]==1)&&(carry==1))

{

buffer[i]=0;

carry=1;

}

}

show();

}

void second()

{

clrscr();

printf(“Enter a Integer numer : “);

scanf(“%d”,&multiplicand);

printf(”
Enter other Integer number : “);

scanf(“%d”,&multiplier);

dec2bin (multiplicand,q);

dec2bin (multiplier,m);

mm2();

}

void mm2()

{

for(i=size2-1;i>=0;i–)

{

deger=m[i];

if(deger==1)

m2[i]=0;

else

m2[i]=1;

}

for(i=size2-1;i>=0;i–)

{

deger=m2[i];

if((deger==1)&&(carry==0))

{

m2[i]=0;

carry=1;

}

else if((m2[i]==0)&&(carry==1))

{

m2[i]=1;

carry=0;

}

else if((m2[i]==0)&&(carry==0))

{

m2[i]=0;

carry=0;

}

else if((m2[i]==1)&&(carry==1))

m2[i]=0;

}

for(i=size2-1;i>=0;i–)

printf(“%d”,m[i]);

printf(”
“);

for(i=size2-1;i>=0;i–)

printf(“%d”,m2[i]);
getch();

}

belgesi-411