How to convert double value to two byte array in c# -


i developing windows forms application. have double value 1.5.that value need convert 2 byte array. when converting using bitconverter.getbytes, getting 8 bytes of data. please refer code below.

double d = 1.5;  byte[] array = bitconverter.getbytes(d); 

double 8 byte value, if have arbitrary double there's no hope you; however, if have restrictions, e.g. value in [0..100] range , has @ 2 digits after decimal point, can encode it:

  // presuming source in [0..100] @ 2 digit after decimal point   double source = 1.5;    // short 2 byte value   short encoded = (short) (source * 100 + 0.5);    byte[] array = bitconvertor.getbytes(encoded);    // decode double   double decoded = encoded / 100.0; 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -