java - first 64 bits of the fractional part of the square root of 2 -


 double i=math.sqrt(2);  double fpart=i-(long)i;   string s=string.valueof(fpart);  s=s.substring(2, s.length()-1);   long b=long.parselong(s);  system.out.println(long.tobinarystring(b));   system.out.println(long.tobinarystring(b).substring(0, 63)); 

i'm getting stringindexoutofboundsexception strig 52 bits long. but, want first 64 bits of fractional part of square root of 2.

unfortunately, forgot 1 important thing.

a 64-bit double made 52 bits of fraction , exponent

that why binary string long 52 bits.

further reading: http://en.wikipedia.org/wiki/double_precision_floating-point_format

in order first 64 bits, might try maths library performs multi-precision operations , result.

don't worry. no -1 question, reasonable, shows didn't study homework :) (or asleep during class).

bye.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -