#define AUID 34567
#include <stdio.h>
#include <math.h>
int main() {
    float id = AUID;
	int floatSize = sizeof(float);
	unsigned char *bits;
	int i, part2;
	int mant = 128;
	bits = (unsigned char*) &id;
	for (part2 = 0; part2 < sizeof(bits); part2++) {
		for(i = 0; i < 8; i++){
			if((bits[part2] & mant) > 0){
				printf("%d", 1);
			mant = mant >>1;
		mant = 128;

This is the code that I have modified...the output is meant to print out the full mantissa bits of the AUID, and also it's floating point value....where am i going wrong???

7 Years
Discussion Span
Last Post by lagirabo

>where am i going wrong???
here, there and everywhere ;)
1. What for floatSize? You never used it.
2. sizeof(bits) is a size of a pointer to unsigned char. It's not bear a relation to the problem. Fortunately it's equal to 4 on 32-bit CPU...
3. 128 as a bit mask is binary 10000000 - it selects MSBit, but you want LSBit.
4. Why + was printed?
5. You are trying to print 32 bits (incorrectly) but float mantissa has 23+1(implicit) bits only.
6. You did not bear in mind mantissa bit order on little-endian CPU...

See http://en.wikipedia.org/wiki/IEEE_754-1985 and try again...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.