This is what I'm running now, but it outputs 1 01111111 11111111111111111111111 which is obviously not -5.8125
Code:
typedef union fi {
unsigned int i;
float f;
}fi;
void displayFloat(float f) {
fi myUnion;
myUnion.f = f;
int theBitValue;
for(int i = 1; i <= 32; i++){
theBitValue = bitValue(myUnion.f,i);
printf("%d", theBitValue);
if(i == 1){
printf(" ");
}
if(i == 9){
printf(" ");
}
}
}
int bitValue(unsigned int num, int index){
unsigned int mask = 1 << index;
num &= mask;
return num >> index;
}