summaryrefslogtreecommitdiffstats
path: root/baseline/source/ammunition/bits.h
diff options
context:
space:
mode:
Diffstat (limited to 'baseline/source/ammunition/bits.h')
-rw-r--r--baseline/source/ammunition/bits.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/baseline/source/ammunition/bits.h b/baseline/source/ammunition/bits.h
new file mode 100644
index 0000000..70cf8bd
--- /dev/null
+++ b/baseline/source/ammunition/bits.h
@@ -0,0 +1,60 @@
1/*
2 FILE NAME: bits.h
3
4 TITLE: Include file of package for work with bits
5
6 DESCRIPTION:
7 This is header file contains macros and the ANSI C prototype
8 definitions for the package for work with bits and bit strings
9 and C++ class for work with bits and bit strings. A bit is
10 given by address (start address) of byte from which counting
11 bits starts and its displacement which is any non negative
12 number of bit from the start address. The most significant bit
13 of the start address byte has number 0. The bit string is
14 given by its first bit and its length in bits.
15
16*/
17
18#ifndef __BITS__
19#define __BITS__
20
21#include "ammunition_limits.h"
22
23/* This macro value returns bit vlaue (0 or 1) with given bit
24 displacement (0, 1, ...). The macro has side effects! Value of
25 `bit_displacement' must be nonegative and can be greater than
26 CHAR_BIT. */
27
28#define BIT(start_byte, bit_displacement)\
29 ((((const char *) (start_byte)) [(bit_displacement) / CHAR_BIT]\
30 >> (CHAR_BIT - 1 - (bit_displacement) % CHAR_BIT)) & 1)
31
32
33/* This macro value sets up new value (must be `0' or `1') of a given
34 bit (bit displacement starts with 0). The macro has side effects!
35 Value of `bit_displacement' must be nonegative and can be greater
36 than CHAR_BIT. */
37
38#define SET_BIT(start_byte, bit_displacement, bit)\
39 (((char *) (start_byte)) [(bit_displacement) / CHAR_BIT]\
40 = (((char *) (start_byte)) [(bit_displacement) / CHAR_BIT]\
41 & ~(1 << (CHAR_BIT - 1 - (bit_displacement) % CHAR_BIT)))\
42 | ((bit) << (CHAR_BIT - 1 - (bit_displacement) % CHAR_BIT)))
43
44int ammunition_is_zero_bit_string ( const void *start_byte,
45 int bit_displacement,
46 int bit_length );
47void ammunition_bit_string_set ( void *start_byte, int bit_displacement,
48 int bit,
49 int bit_length );
50void ammunition_bit_string_copy ( void *to, int to_bit_displacement,
51 const void *from, int from_bit_displacement,
52 int bit_length );
53void ammunition_bit_string_move ( void *to, int to_bit_displacement,
54 const void *from, int from_bit_displacement,
55 int bit_length );
56int ammunition_bit_string_comparison ( const void *str1, int bit_displacement1,
57 const void *str2, int bit_displacement2,
58 int bit_length );
59
60#endif /* #ifndef __BITS__ */