diff options
author | Bdale Garbee <bdale@gag.com> | 2017-04-24 18:22:03 -0600 |
---|---|---|
committer | Bdale Garbee <bdale@gag.com> | 2017-04-24 18:22:03 -0600 |
commit | b91f67005709cb7f65e0a461b49b5cb0952cb391 (patch) | |
tree | e9f6c0f30a81cf30a9cfd52887171168f7830f85 /src/cortexelf-v1/ao_flip_bits.5c | |
parent | 1e956f93e0c9f8ed6180490f80e8aead5538f818 (diff) | |
parent | 8a10ddb0bca7d6f6aa4aedda171899abd165fd74 (diff) |
Merge branch 'branch-1.7' into debian
Diffstat (limited to 'src/cortexelf-v1/ao_flip_bits.5c')
-rw-r--r-- | src/cortexelf-v1/ao_flip_bits.5c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/cortexelf-v1/ao_flip_bits.5c b/src/cortexelf-v1/ao_flip_bits.5c new file mode 100644 index 00000000..cd5507cc --- /dev/null +++ b/src/cortexelf-v1/ao_flip_bits.5c @@ -0,0 +1,24 @@ +#!/usr/bin/nickle + +int flip_bits(int a, int n) +{ + int result = 0; + for (int pos = 0; pos < n; pos++) + if ((a & (1 << pos)) != 0) + result |= (1 << (n - 1 - pos)); + return result; +} + +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 < 1 << n; i++) { + printf (" 0x%02x,", flip_bits(i, n)); + if ((i & 0xf) == 0xf) + printf("\n"); + } + printf("};\n"); +} + +print_flip_bits("ao_flip_bits", 8); +print_flip_bits("ao_flip_bits", 2); |