Code:
#include <stdio.h>
#include <Math.h>
void *signedtwobit(char *x, char *y);
void thirtytwomultiply(char *x, char *y);
int main(void) {
//-------------------problem1---------------------
printf("Entered question 1.\n\n");
char a[]={0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
char b[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
char *p, *q;
p=a;
q=b;
signedtwobit(p,q);
char c[]={0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
char d[]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
p=c;
q=d;
signedtwobit(p,q);
char e[]={1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
char f[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
p=e;
q=f;
signedtwobit(p,q);
char g[]={1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
char h[]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
p=g;
q=h;
signedtwobit(p,q);
char i[]={0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
char j[]={1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
p=i;
q=j;
signedtwobit(p,q);
//--------------------------------------------------
//-----Question 2-----------------------------------
printf("Entered question 2.\n\n");
char xa[]={0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
char ya[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0};
p=xa;
q=ya;
thirtytwomultiply(p,q);
printf("\nTest Case 2\n");
char xb[]={0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
char yb[]={1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
p=xb;
q=yb;
thirtytwomultiply(p,q);
char xc[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
char yc[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
p=xc;
q=yc;
thirtytwomultiply(p,q);
char xd[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1};
char yd[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0};
p=xd;
q=yd;
thirtytwomultiply(p,q);
char xe[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
char ye[]={1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
p=xe;
q=ye;
thirtytwomultiply(p,q);
//---------------------------------------------------
//--------------Question 3---------------------------
//---------------------------------------------------
//--------------Question 4---------------------------
double a;
a=2.71828;
a=1.61803;
a=-1.41421;
a=-1.73205;
a=-2.23606;
//---------------------------------------------------
}
void *signedtwobit(char *x, char *y) {
char s[33];
int i;
char *p, *q, *z;
p=x;
q=y;
printf(" ");
for (i=0; i<=31; i++) {
printf("%d ", *p);
p++;
}
printf("\n");
printf("+ ");
for(i=0; i<=31; i++) {
printf("%d ", *q);
q++;
}
printf("\n");
p--;
q--;
//----start adding----
for (i=32; i>=1; --i) {
s[0]=0;
s[i]=*p+*q;
if (s[i]==2) {
if (i==1) {
s[0]=1;
s[1]=0;
}
else {
s[i]=0;
p--;
*p=*p+1;
p++;
}
}
else if (s[i]==3) {
if (i==1) {
s[0]=1;
s[1]=1;
}
else {
s[i]=1;
p--;
*p=*p+1;
p++;
}
}
p=p-1;
q=q-1;
}
//-----end adding------
z=s;
for (i=0;i<=65;i++){
printf("-");
}
printf("\n");
for (i=0; i<=32; i++) {
printf("%d ", *z);
z++;
}
printf("\n\n\n\n");
}
void thirtytwomultiply(char *x, char *y) {
char s[64]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
char t[64];
int i;
char *p, *q, *r, *z;
p=x;
q=y;
z=s;
printf(" ");
for (i=0; i<=31; i++) {
printf(" ");
}
for (i=0; i<=31; i++) {
printf("%d", *p);
p++;
}
printf("\n");
printf("* ");
for (i=0; i<=31; i++) {
printf(" ");
}
for(i=0; i<=31; i++) {
printf("%d", *q);
q++;
}
printf("\n");
for (i=0;i<=65;i++){
printf("-");
}
printf("\n");
p=x;
q=y;
z=s;
int j=0;
int k=0;
int l=0;
r=t;
for (i=0; i<64; i++) {
*r=0;
r++;
}
q=q+31;
//-------------------------------------------------------------------
for (j=1; j<=32; j++){
q--; //decrements q
//-------start making r--------
printf("enter making r\n");
for (i=0; i<=63; i++) {
*r=0;
r++;
}
r=r-64;
for (i=32-k; i>0; i--) {
*r=0;
r++;
}
for (i=0; i<32; i++) {
*r=*p;
r++;
p++;
}
for (i=k; i>0; i--) {
*r=0;
r++;
}
//--------stop making r--------
p=p-32; //reset p and r to base
r=r-64;
k++; //shift left
//----------------start addition----------------------
printf("enter addition\n");
if (*q==1) {
printf("Q=1\n");
//add to z
for (l=64; l>=1; l--) {
*z=*r+*z;
if (*z==2) {
*z=0;
r--;
*r=*r+1;
r++;
}
else if (*z==3) {
*z=1;
r--;
*r=*r+1;
r++;
}
z++;
r++;
}
}
else {
*z=*z;
}
//--------end addition-------
printf("\n\n");
printf("reenter loop\n");
}
z=z-64;
r=r-64;
printf(" ");
for (i=0;i<64;i++) {
printf("%d",*z);
if(i<63) {
z++;
}
}
printf("\npreparing to exit method\n");
}