diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2014-08-29 01:19:08 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2014-08-29 01:19:08 -0400 |
commit | c9024359e0808ad3867ddce9aab0b2d5ae557a5b (patch) | |
tree | 91c733cf94626533cb4c2c1cf2678e1122b53ce4 /bits.c | |
parent | 43b3626428d55493b22a1b60704c3d1ab55c22de (diff) | |
download | gpsd-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.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -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) { |