how can i get the last bit of a double
Sep 13, 2010 at 8:41am
how can i get the last bit of a double?
i want to take a "or" operation with it.
Sep 13, 2010 at 12:55pm
1 2
|
double d; //assign to whatever num you want
char lastbit = d & 0x1;
|
Sep 13, 2010 at 1:24pm
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&’
|
Sep 13, 2010 at 1:28pm
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 Sep 13, 2010 at 1:31pm
Topic archived. No new replies allowed.