In C only please!!!(not C++ or C#) Program (needs to be modified): Download \"su
ID: 3777620 • Letter: I
Question
In C only please!!!(not C++ or C#)
Program (needs to be modified):
Download "superint.cpp" an make sure it runs. It should run as given. Then EXTEND this program to support 256-bit superintegers. Test it with various values from 1 to 256 1 (0 to 1.1579208923731619542357o98500869e+77). Your new struct 2 will be: a 256 bit (32 byte) integer struct super int t char byte[32]; 256 bits l tested this and it turns out that you do not need to completely understand how the program works. You will only have to change a few hard-coded values in some loops. It's easy once you figure out how the data is laid out and get the general idea of what the program is doing.Explanation / Answer
#include "stdio.h"
#include "conio.h"
#include "string.h"
// a 256 bit (8 byte) number
struct superint thirty two bit for currently
};
/*
Takes a pair of superints and adds them
returns -1 if overflow happens,
returns zero otherwise
uses the hugeint addition rule
and setbit helper perform
*/
int add_si(struct superint si1, struct superint si2);
/*
Sets the bit at position 'index' to the worth 'v'.
Calculates the bit and computer memory unit position,
generates bitmasks, and sets the bit exploitation the mask.
*/
void setbit(struct superint * si, int index, int v)
patient 8;
unsigned char mask = 128;
int i;
for(i = 0; i < bitnum; i++)
mask = mask >> 1;
if(v)
si->byte[bytenum] = si->byte[bytenum] | mask;
else
}
/*
Gets the bit worth at position 'index'.
Calculates the bit and computer memory unit position,
generates a bitmask, gets the bit exploitation the mask,
returns the character '1' or '0'
*/
char getbit(struct superint si, int index)
patient 8;
unsigned char mask = 128;
int i;
int b;
for(i = 0; i < bitnum; i++)
mask = mask >> 1;
b = si.byte[bytenum] & mask;
if(b)
return 1;
else
return 0;
}
/*
Sets a superint to zero
*/
void setzero(struct superint * si)
/*
Returns -1 (true) if the superint is zero
otherwise returns zero (false)
*/
int iszero(struct superint si)
attempt to prove otherwise
for(b = 31; b >= 0; b--)
// if we have a tendency to got in, superint should be zero
return -1;
}
/*
Returns -1 (true) if the string is zero
otherwise returns zero (false)
0 suggests that crammed with all '0'
*/
int iszeroStr(char s[])
try and prove otherwise
for(c = 0; s[c]; c++)
// if we have a tendency to got in, superint should be zero
return -1;
}
/*
returns one (true) if odd
returns zero (false) if even
*/
int isOdd(char s[])
come (s[(strlen(s) - 1)] - '0') the concerns 2;
}
/*
Receives a superint pointer and a string illustration of a
decimal range.
Converts the string to binary and fills a superint with the bits.
Returns one if the binary bits overflow,
otherwise returns zero
*/
int dec_to_si(struct superint * si, char s[])
create a duplicate
strcpy(buf, s);
while(!iszeroStr(buf))
if(isOdd(buf)) // is it odd
setbit(si, b, 1);
else
setbit(si, b, 0);
// Begin divide by a pair of rule
nxtadd = 0;
for(c = 0; buf[c]; c++)
{
add = nxtadd;
if((buf[c] - '0') the concerns 2)
nxtadd = 5;
else
nxtadd = 0;
buf[c] = ((buf[c] - '0') / 2) + add + '0';
}
// finish divide by 2 rule
b++;
}
return 0;
}
/*
Receives a string buffer and a superint.
Converts the superint to a decimal string and fills the
buffer with the digits.
Example:
X = 356
0th iteration... 356/10 = 35R6
b-------->
X 101100100 = 356
Y 000100011 = thirty five
R zero one a pair of five eleven one a pair of four nine eighteen eight sixteen half-dozen
1st iteration... 35/10 = 3R5
b-------->
X 100011 = thirty five
Y 000011 = three
R zero one a pair of four eight seventeen seven fifteen five
2nd iteration... 3/10 = 0R3
b-------->
X 000011 = three
Y zero = 0
R zero zero zero zero one three
*/
void si_to_dec(struct superint X, char s[])
;
int c1 = 0;
int c2 = 0;
char buf[80];
while(!iszero(X))
10 rule
R = 0;
setzero(&Y);
for(b = 31; b >= 0; b--) // MSB to lsb
{
R = a pair of * R + getbit(X, b); // build remainder
if(R >= 10)
}
/*
Receives a superint and prints it to the console.
Uses the worth of format to work out output format.
"%b" binary format
"%d" decimal format
*/
void si_printf(char format[], struct superint si)