#include <cstdint>
#include <iostream>
#include <string>
#include <vector>
#include <cstdint>

uint32_t read_u32_le(uint8_t* bytes)
{
    uint32_t value;
    value = bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24);
    return value; 
}
int32_t read_s32_le(uint8_t* bytes)
{
    int32_t value;
    value = bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24);
    return value; 
}
int main()
{
    // written in binary format is the following bytes:
    // 68 172 0 0
    
    unsigned char b1 = 68;
    unsigned char b2 = 127;
    unsigned char b3 = 0;
    unsigned char b4 = 0;
    
    std::cout << (int)b1 << " " << (int)b2 << " " << (int)b3 << " " << (int)b4 << std::endl;
    
    uint8_t bytes[4] = {b1, b2, b3, b4};
    // prints -21436:
    int32_t sampleRate_s = read_s32_le(bytes);
    std::cout << sampleRate_s << std::endl;
    
    // prints correctly 44100:
    uint32_t sampleRate_u = read_u32_le(bytes);
    std::cout << sampleRate_u << std::endl;

}