summaryrefslogtreecommitdiff
path: root/bits.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2014-08-29 01:19:08 -0400
committerEric S. Raymond <esr@thyrsus.com>2014-08-29 01:19:08 -0400
commitc9024359e0808ad3867ddce9aab0b2d5ae557a5b (patch)
tree91c733cf94626533cb4c2c1cf2678e1122b53ce4 /bits.c
parent43b3626428d55493b22a1b60704c3d1ab55c22de (diff)
downloadgpsd-c9024359e0808ad3867ddce9aab0b2d5ae557a5b.tar.gz
Wrote code and test for a function to left-shift bit arrays).
To be used for handling AIS Type 25 and 26 messages.
Diffstat (limited to 'bits.c')
-rw-r--r--bits.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/bits.c b/bits.c
index 8db4a4aa..775b9682 100644
--- a/bits.c
+++ b/bits.c
@@ -14,6 +14,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
+#include <string.h>
#include "bits.h"
@@ -130,6 +131,31 @@ void putbef32(char *buf, int off, float val)
/*@+shiftimplementation -ignoresigns@*/
}
+
+void shiftleft(unsigned char *data, int size, unsigned short left)
+{
+ /*@+matchanyintegral +ignoresigns -type -shiftnegative@*/
+ unsigned char *byte;
+
+ if (left >= CHAR_BIT) {
+ size -= left/CHAR_BIT;
+ memmove(data, data + left/CHAR_BIT, size);
+ left %= CHAR_BIT;
+ }
+
+ for (byte = data; size--; ++byte )
+ {
+ unsigned char bits;
+ if (size)
+ bits = byte[1] >> (CHAR_BIT - left);
+ else
+ bits = 0;
+ *byte <<= left;
+ *byte |= bits;
+ }
+ /*@-matchanyintegral -ignoresigns +type +shiftnegative@*/
+}
+
#ifdef __UNUSED__
void putbed64(char *buf, int off, double val)
{