X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fcortexelf-v1%2Fao_flip_bits.5c;h=cd5507cc0059d74b7b077e3adde641589eeafd47;hb=338372b97d441c30d2a23df540163a66a7f8d8c0;hp=26900893b330d74c24d1dc9540dda616034b1674;hpb=5bb9cf38c84663713c178f54b684d40b6c00b11d;p=fw%2Faltos diff --git a/src/cortexelf-v1/ao_flip_bits.5c b/src/cortexelf-v1/ao_flip_bits.5c index 26900893..cd5507cc 100644 --- a/src/cortexelf-v1/ao_flip_bits.5c +++ b/src/cortexelf-v1/ao_flip_bits.5c @@ -1,19 +1,24 @@ #!/usr/bin/nickle -int flip_bits(int a) +int flip_bits(int a, int n) { int result = 0; - for (int pos = 0; pos < 8; pos++) + for (int pos = 0; pos < n; pos++) if ((a & (1 << pos)) != 0) - result |= (1 << (7 - pos)); + result |= (1 << (n - 1 - pos)); return result; } -printf ("static uint8_t ao_flip_bits[256] = {\n"); +void print_flip_bits(string name, int n) { + printf ("static const uint8_t %s_%d[%d] = {\n", name, n, 1 << n); -for (int i = 0; i < 256; i++) { - printf (" 0x%02x,", flip_bits(i)); - if ((i & 0xf) == 0xf) - printf("\n"); + for (int i = 0; i < 1 << n; i++) { + printf (" 0x%02x,", flip_bits(i, n)); + if ((i & 0xf) == 0xf) + printf("\n"); + } + printf("};\n"); } -printf("};\n"); + +print_flip_bits("ao_flip_bits", 8); +print_flip_bits("ao_flip_bits", 2);