2

Using the following code to convert Flow_Rate from a 'double' to a byte array I received the output: [B@6a2b8b42

How do I check that the output is correct?

private double Flow_Rate= 8;   

OFVendor of_vendor = new OFVendor(); 
byte [] rate = ByteBuffer.allocate(8).putDouble(Flow_Rate).array(); 
of_vendor.setData(rate);  

Logger.stderr("ZB---->> ClientChannelWatcher::handleConnectedEvent OFVendor setData() : "+rate);
Emma
  • 57
  • 1
  • 8
Xobiiii
  • 21
  • 7

1 Answers1

1

I assume your goal is to put the "bits" of your double into a binary buffer.

If so, your best bet is probably to use a ByteBuffer

import java.nio.ByteBuffer;
...

private double Flow_Rate= 8.0; 
...

byte[] rate_buffer = new byte[8];
ByteBuffer.wrap(rate_buffer).putDouble(Flow_Rate); 
... 

PS: [B@6a2b8b42 is just how any object is printed - it has nothing directly to do with the contents of your byte array.

FoggyDay
  • 11,962
  • 4
  • 34
  • 48
  • Additional note: if you want to print the contents of the array, three methods are 1) use a "for ()" loop, 2) use JDK 1.5++ [java.util.Arrays.toString()](http://www.wikihow.com/Print-an-Array-in-Java), or 3) use [Arrays.deepToString()](http://www.tutorialspoint.com/java/util/arrays_deeptostring.htm). – FoggyDay Jun 11 '14 at 04:54
  • Thanks, this code is working fine as before i told you that was also giving the same output. I have also a question, after data is converted in to array of byte then i need to parse that data to another function and the argument of that function is of ByteBuffer type, i converted it also by using ByteBuffer data = ByteBuffer.wrap(rate); there it is giving the exception of java.nio.BufferOverflowException how can i solve this? If you know please let me know Thanks for your quick response. – Xobiiii Jun 11 '14 at 05:19