Forum guidelines
zozo ahmed
convert each location from array of bytes to double
Posted By zozo ahmed on 07 Jan 2014
I need to convert each location of bytes arrays to double ,it can not run with Bitconverter:
byte[,] R = new byte[width, height]; 
byte[,] G = new byte[width, height]; 
byte[,] B = new byte[width, height];  
double[,] Y1 = new double[width, height]; 
for (int x = 0; x < width; x++) 
 for (int y = 0; y < height; y++) 
           double ee = BitConverter.ToDouble(R[x, y], x, y);
           double ee1 = BitConverter.ToDouble(G[x, y], x, y); 
           double ee2 = BitConverter.ToDouble(B[x, y], x, y);     
           Y1[x, y] = (0.39 * ee) + (0.59 * ee1) + (0.12 * ee2);
Is there method for convert each location of byte array to double??


  • 1
  • 0
Re: convert each location from array of bytes to double
Posted By Vulpes on 07 Jan 2014   Accepted Answer
Well, a double is represented by 8 bytes internally using a standard format.

So, when you say that you want to convert the bytes to doubles, do you mean that:

1. you want to (somehow) take the bytes, eight at a time, and convert them to a double using the internal representation; or

2. you want to convert each byte to a double with the same value - so a byte of 1 would become the double 1.0.

If it's the latter, then the solution is simply:

for (int x = 0; x < width; x++) 
   for (int y = 0; y < height; y++) 
       Y1[x, y] = 0.39 * R[x,y] + 0.59 * G[x,y] + 0.12 * B[x,y];

C# Corner Annual Conference 2016


Spire.Doc - Free .NET Word API
Use Spire.Doc to create, read, write, print, and convert word documents to OpenXML, RTF, TXT, XPS, EPUB, EMF, HTML, Image and PDF.