Reputation: 49
I have the char
array:
char* chararray = new char[33];
and the int
:
int exponent = 11111111;
What I want to do, but am confused as to how, is: input the values of exponent
into chararray
. With the restrictions that exponent
has to take up the 2nd to 9th values of chararray
. chararray
will be all 32 0s,and I want it to become 0xxxxxxxx0000....00, the x's being the 8 digits in exponent
.
Furthermore, no build-in conversion functions like atof or atoi. I also want to avoid using Floats or doubles not that you'd really need to.
Note, this is for making IEEE754 32bit values to get some understanding.
Will edit for additional details or clarification if needed.
Upvotes: 1
Views: 659
Reputation: 1922
Try this after initializing the array with '0'
:
for(int i=9; i>=2; i--) {
chararray[i] = (exponent%10) + '0';
exponent = exponent/10;
}
chararray[32] = '\0';
Upvotes: 1