| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 
 | #include <iostream>
#include <array>
 
std::array<unsigned, 4> encode(std::array<unsigned, 3> const & octets)
{
    return {
        (octets[0] & 0xFC) >> 2,
        ((octets[0] & 0x03) << 4) + ((octets[1] & 0xF0) >> 4),
        ((octets[1] & 0x0F) << 2) + ((octets[2] & 0xC0) >> 6),
        octets[2] & 0x3F
    };
}
 
std::array<unsigned, 3> decode(std::array<unsigned, 4> const & indexes)
{
    return {
        ((indexes[0] << 2) & 0xFC) + ((indexes[1] >> 4) & 0x03),
        ((indexes[1] << 4) & 0xF0) + ((indexes[2] >> 2) & 0x0F),
        ((indexes[2] << 6) & 0xC0) + (indexes[3] & 0x3F)
    };
}
 
int main() {
    for (unsigned i1 = 0; i1 < 0b111111; ++i1) {
        for (unsigned i2 = 0; i2 < 0b111111; ++i2) {
            for (unsigned i3 = 0; i3 < 0b111111; ++i3) {
                std::array<unsigned, 3> const arr{{i1,i2,i3}};
                if (arr != decode(encode(arr))) {
                    std::cerr << "noop\n";
                    return 1;
                }
            }
        }
    }
    std::cout << "ok\n";
    return 0;
} | 
Partager