Employers - Post Free Jobs
Forum guidelines
  • Home
  • »
  • C# Language
  • »
  • convert each location from array of bytes to double
AuthorQuestion
convert each location from array of bytes to double
Posted 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??

 

AuthorReply
Vulpes
  • 1
  • 0
accepted
Re: convert each location from array of bytes to double
Posted 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];
   }

Employers - Post Free Jobs

SPONSORED BY

Offshore Software and Database Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.