I am implementing a MidiReader And it need me to read weather MSB First or LSB First UInts(8, 16, 32 or 64). I know little about binary and types so I'm currently copying other's code from C#.
class ByteArrayReader
{
public:
unsigned char* ByteArray;
unsigned int Size;
unsigned int Index = 0;
ByteArrayReader(unsigned char* byteArray)
{
if (byteArray == NULL)
{
throw byteArray;
}
ByteArray = byteArray;
Size = (unsigned int)sizeof(byteArray);
Index = 0;
}
char inline Read()
{
return ByteArray[Index++];
}
void inline Forward(unsigned int length = 1)
{
Index += length;
}
void inline Backward(unsigned int length = 1)
{
if (length > Index)
{
throw length;
}
Index -= length;
}
bool operator==(ByteArrayReader) = delete;
};
These are what I copied:
uint16_t inline ReadUInt16()
{
return (uint16_t)((Read() << 8) | Read());
}
uint32_t inline ReadUInt32()
{
return (uint32_t)((((((Read() << 8) | Read()) << 8) | Read()) << 8) | Read());
}
But it's said that one of it reads MSB First UInt. So I want to ask how to read UInt types from binaries elegantly, also learning how uint is represented in bytes.