0

I need to convert a double to an array of bytes in little endian, keeping the decimal places. To do this, I need to use bitwise operations on the double. However, I cannot do >> or & to a double. Since long is the only other type that can be used in bitwise operations and is 64bit, I need to convert a double to a long in such a way that:

011010101010.1001010010100101001010010100101001010010100101001010

becomes

011010101010 1001010010100101001010010100101001010010100101001010L

instead of

000000000000 0000000000000000000000000000000000000000011010101010L

ungato
  • 153
  • 2
  • 12
  • Since this is NOT a duplicate of that question, I will answer in a comment. Use the static method `Double.doubleToLongBits(yourDouble)`. Or perhaps the doubleToRawLongBits variant. Except I'm not sure this is what you want??? – user949300 Oct 25 '15 at 17:08
  • 1
    @user949300 If it isn't a duplicate, how come your answer appears there? – user207421 Oct 25 '15 at 17:34
  • 1
    How are you going to represent/manage the binary point location - indicated by a space in your example output? – Patricia Shanahan Oct 25 '15 at 21:14
  • @EJP Because you changed the link in the "already has an answer here" section. The original link went to a different question. I agree that the new, corrected link is indeed a duplicate. – user949300 Oct 26 '15 at 22:23
  • @PatriciaShanahan I won't. The purpose of the space was to line up the binary digits. – ungato Oct 28 '15 at 21:48

0 Answers0