I want to read 8 bits at a time from a file in little endian format, I think my cpu is also little endian so I need not to worry about the endianess, right?
what I am reading are numbers, intensity values of RGGB CFA from a RAW12 file.
Here is my code -
uint8_t first8bits, second8bits, third8bits;
file.read((char*)&first8bits, sizeof(uint8_t));
file.read((char*)&second8bits, sizeof(uint8_t));
file.read((char*)&third8bits, sizeof(uint8_t));
Red_channel = (first8bits) << 4 | (second8bits & 0xF0) >> 4;
Green_channel = (second8bits & 0x0F) | (third8bits);
I have seen others reading it 8 bits into a char array and then converting it to a number, how do I do that? Since the machine I am testing the code of is little endian I think I dont need to do byte swap but what if some other person tests this code on big endian machine, how do I find at runtime if the machine is little endian or big endian?
Any help would me much appreciated.