summaryrefslogtreecommitdiff
path: root/src/cortexelf-v1/ao_flip_bits.5c
blob: cd5507cc0059d74b7b077e3adde641589eeafd47 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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);