reading in pixels two bits at a time?

I have a programming challenge that involves reading in pixels from a PGM file. PGM is a simple format for black-and-white photographs.
The programs asks to do the following:
Read 16 pixels of input. From this, extract len, the length of the OUTPUT file. This will
be a long int, (4 bytes) stored two bits per pixel.
How can I read in the pixels and store them two bits at a time into len?

Also, here are some of the variables we have.
typedef char pixel;
class PGM {
char filetype[3]; // Should be "P5".
int width;
int height;
int maxgrey; // Should be 255
pixel* image; // Dynamically allocated array of width*height pixels.

};

Any suggestions? thanks
I would guess that your question is to read two bytes for the length.

Use [u]int16_t. See:

http://www.cplusplus.com/reference/cstdint/

The problem is the endianness:

https://en.wikipedia.org/wiki/Endianness
thanks....but someone told me we are supposed to be doing something like this: unsigned char pair = pixel & 0x03
Topic archived. No new replies allowed.