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 add(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)


  {


            add();


            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(”

Your result is %d”,res);


}


 


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;


}


 


void add(void)


{


 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();


 printf(” Added..”);


}


 


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
Belgeci

Share
Published by
Belgeci

Recent Posts

Fecr-i ati Edebiyatı

FECRİ ATİ EDEBİYATI   Servet-i fünun edebiyatının devamı niteliğinde olan fecr-i ati topluluğu,1909 yılında ortaya…

5 saat ago

İlk Cep Telefonu

ÖZELLİKLER: Boyut: 28x8x6 cm Ağırlık: 850gr Ekran: Yok Devre sayısı: 30 Konuşma süresi: 35 dakika…

17 saat ago

Basic Grammar-Questions

There are two kinds of questions: yes or no questions and wh- questions. You ask…

1 gün ago

Basic Grammar-Positive And Negative Sentences

A positive sentence tells you that something is so. A sentence that tells you something…

2 gün ago

Basic Grammar-The Imperative

Use the base form of a verb to give commands or make direct requests. This…

2 gün ago

Basic Grammar-Sentences

A sentence is a group of words that expresses a complete thought. A sentence must…

3 gün ago