views:

77

answers:

2

I am currently working on visual c++ 2008 express edition. My project is based on reading satellite images and applying image processing on them. Each image file has an ".0FM" format and is of 8Mb size.

Until now I have been able to read the file (i.e., "*.0FM" ) using a FileStream and into a Byte array, the size of the byte array is 8,000,000.

I then converted each element off the byte array to Decimal, so now each element in the array has values ranging from 0 - 255. Now I have to convert each of these Decimal values in the array into its binary values. E.g., 86 should be converted into 1010110

I am really stuck here. I tried System::Decimal::GetBits() method but all this method does is that it stores 86 into bits[0],

Decimal d = 86;
array<int>^ buf_bits = Decimal::GetBits(d);

This code results in the storing of value 86 in buf_bits[0], I do not get 1010110.

A: 

You don't ever work with the bits directly. Leave them as bytes. If you need to check flags or something use something like the following technique:

byte mask = 8;
if(myFileData[SomeIndex] & mask > 0)
   // Bit in 4th position is "ON";
Spencer Ruport
A: 

First, if your values are ranging from 0 to 255, you should use byte (or unsigned char). Than, you need to use the Shift left / Shift right operators.

in psuedo code, where num is your 0-255 byte:

mask = 1b;
bits = new array[sizeof(BYTE)];
for (i=0; i < sizeof(BYTE); i++)
{
    tmp = num & mask;
    bits[i] = tmp >> i;
    mask = mask << 1;
}
sagie
Hi..actually i have to display these byte values in picturebox control. So, i guess that if i convert the byte values into bits then it would possibly easy to display the byte values in the picturebox control..
JAYMIN
in the bits array you have 0s and 1s. use them in any way you want. print directly into picturebox may be difficult, because you need an image the its pixels represent a graphical 0s and 1s.
sagie