In particular the above seems very pointless...Code:mantissa = mantissa << 9; mantissa = mantissa >> 9;
--
Mats
In particular the above seems very pointless...Code:mantissa = mantissa << 9; mantissa = mantissa >> 9;
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
okay I fixed all the errors I have, now how do I translated the mantissa into hexadecimals. like for instance if it's -10 then it should be 0xa00000 in the mantissa
Last edited by -EquinoX-; 03-03-2008 at 01:20 PM.
Your bits are in the wrong position, that's why it seems you are getting "excess."
You can use my function for debugging:
It will print all bits of a number. Make sure there are no "0" to the right-most, because if there it, you didn't shift it right.Code:void PrintBits(uint32_t nNumber) { char Binary[sizeof(nNumber) * 8 + 1] = {0}; char Binary2[sizeof(nNumber) * 8 + 1] = {0}; for (int i = sizeof(nNumber) * 8 - 1; i >= 0; i--) { if (nNumber & (0x1 << i)) Binary[i] = '1'; else Binary[i] = '0'; } for (int i = sizeof(nNumber) * 8 - 1, j = 0; i >= 0; i--, j++) Binary2[j] = Binary[i]; for (int i = 0; i < sizeof(nNumber) * 8; i++) { if (i == 1) cout << " "; else if (i == 1 + 8) cout << " "; cout << Binary2[i]; } cout << "\n"; }
Shift it all the way to the right. And be careful not to shift too much.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
I think what brewbuck referred to was if you extracted a number such as
1111 11111 0000 0000
Shift left 9 times and we get:
1000 0000 0000 0000
Shift right 9 times and we get:
0000 0001 0000 0000
Unintentionally destroyed data.
But it depends on the size. It it was 32-bit, obviously this wouldn't happen.
yes I am doing this on a 32 bit machine
Well, as I mentioned, for the number -10.0, you should get:
Mantissa 0x00200000
Exponent 0x0082
Sign 0x01
If you don't, then there's a bug somewhere in the code. Look at the results you are getting and compare them to these. If they don't match, then they're wrong.
as I said the hidden value, which is 1. x x x x x is included here
my other question is that say that I have an unsigned int 126 and I want to substract that with the int 127 so the result will be -1, how would I do this??
Last edited by -EquinoX-; 03-03-2008 at 05:24 PM.