how can i get the last bit of a double
how can i get the last bit of a double?
i want to take a "or" operation with it.
1 2
|
double d; //assign to whatever num you want
char lastbit = d & 0x1;
| |
1 2 3
|
g++ test.cpp
test.cpp: In function ‘int main(int, char**)’:
test.cpp:10: error: invalid operands of types ‘float’ and ‘int’ to binary ‘operator&’
| |
char lastbit = d & 0x1;
Nice try but it won't work :P You can't use bitwise operators with doubles or floats.
And what do you mean with 'last bit'? Check this out:
http://en.wikipedia.org/wiki/Single_precision
The number is 0.15625 but the 'last bit' (the least significant bit of the fraction part) is zero.
Maybe what you want is the last
digit.
Last edited on
Topic archived. No new replies allowed.