aboutsummaryrefslogtreecommitdiffstats
path: root/src/flip_bits.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/flip_bits.c')
-rw-r--r--src/flip_bits.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/flip_bits.c b/src/flip_bits.c
new file mode 100644
index 0000000..f33994e
--- /dev/null
+++ b/src/flip_bits.c
@@ -0,0 +1,29 @@
+#include <stdint.h>
+#include "flip_bits.h"
+
+static uint8_t flip_table[256];
+
+void init_flip_bits(void)
+{
+ int i,k;
+
+ for (i = 0 ; i < 256 ; i++) {
+ uint8_t sample = 0 ;
+ for (k = 0; k<8; k++) {
+ if ( i & 1 << k ) sample |= 0x80 >> k;
+ }
+ flip_table[i] = sample;
+ }
+}
+
+uint8_t *flip_buf_bits(uint8_t *buf, int len)
+{
+ int i;
+ uint8_t *start = buf;
+
+ for (i = 0 ; i < len; i++) {
+ buf[i] = flip_table[(uint8_t)buf[i]];
+ }
+
+ return start;
+}