I got a bit trouble with my c code. I am trying to extract the sign, exponent and the mantissa. So far it worked out for sign and exponent. The problem begins with mantissa. For example, let's take -5.0. 1 bit for sign, 8 bits for the exponent and 23 bits for the mantissa. This is the binary notation of -5.0:
1 10000001 01000000000000000000000
1 = sign
10000001 = exponent
01000000000000000000000 = mantissa.
I wanna return the bits of the mantissa back.
static int fpmanitssa(uint32_t number) {
uint32_t numbTemp = 8388607;
number = number & numbTemp; //bitwise AND, number should be 2097152.
int numbDiv;
int leftover;
char resultString[23];
size_t idx = 0;
do {
numbDiv = number/2;
leftover = number % 2;
resultString[idx++] = leftover;
number = numbDiv;
} while (number != 0);
return resultString;
What I get as result are negative numbers. I don't know why it isn't working. Could you please help to find the problem?
regards Hagi